0

here is the html

<div data-v-026c45df="" class="col text-undefined">682ドル.0</div>

I need the '682ドル.0'. I have tried :

start_aum = driver.find_element_by_class_name('col text-undefined').get_attribute
print(start_aum)

and


start_aum = driver.find_element_by_css_selector('col text-undefined').get_attribute
print(start_aum)

both return


selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".col text-undefined"}
 (Session info: chrome=88.0.4324.190)

I am open to using beautiful soup or selenium but I can't seem to understand why I am having problems selecting the element.

asked Mar 9, 2021 at 19:02

3 Answers 3

1

There might some issue with the element visibility etc., but I can't see the whole code, so I'll react to only what's in your question:

  • get_attribute is a method, you are not calling it, you'd need something like get_attribute("class")
  • 682ドル.0 is not an attribute, it's text, you need to get it with .text, e.g. driver.find_element_by_css_selector('.col.text-undefined').text
  • in find_element_by_css_selector('col text-undefined') there's an incorrect selector, the correct one would be .col.text-undefined
answered Mar 9, 2021 at 19:28
5
  • to be able to know if it is an issue with element visibility do you need to see the html, or my script? Commented Mar 9, 2021 at 20:09
  • I'd fix these things first, then study a bit along these topics stackoverflow.com/a/59130336/10401931 and then possibly change the script further. Commented Mar 9, 2021 at 21:41
  • After doing some research I am trying to utilize this line of code from the link you attached for me. check_box = WebDriverWait(Browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tableview-3687-record-2128"]/tbody/tr/td[1]/div/div'))) check_box.click() but I am getting the error that 'By' is not defined. I found the dependencies for the other bit in that line of code but I'm not sure what I need in order to use the 'By' part Commented Mar 10, 2021 at 15:05
  • Does this answer your question? selenium-python.readthedocs.io/locating-elements.html from selenium.webdriver.common.by import By You also have one extra pair of brackets there, although Python should not complain in this situation. Commented Mar 10, 2021 at 15:59
  • also worth noting that find_element_by_class_name() can't take multiple classes: stackoverflow.com/questions/37771604/… Commented Mar 10, 2021 at 21:46
0

Your locator is wrong, use

 start_aum = driver.find_element_by_css_selector('[class="col text-undefined"]').Text
 print(start_aum)
answered Mar 11, 2021 at 10:01
0
driver.find_element_by_css_selector(".col.text-undefined").text
answered Mar 15, 2021 at 2:27
3
  • What would be the difference between this and pavel's answer? Commented Mar 15, 2021 at 3:03
  • Please add some explanation to the answer that might be helpful. Commented Mar 15, 2021 at 4:04
  • Pavels answer is correct, no difference Commented Mar 15, 2021 at 11:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.