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.
3 Answers 3
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 likeget_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
-
to be able to know if it is an issue with element visibility do you need to see the html, or my script?MeaColley– MeaColley2021年03月09日 20:09:30 +00:00Commented 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.pavelsaman– pavelsaman2021年03月09日 21:41:22 +00:00Commented 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' partMeaColley– MeaColley2021年03月10日 15:05:17 +00:00Commented 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.pavelsaman– pavelsaman2021年03月10日 15:59:28 +00:00Commented Mar 10, 2021 at 15:59 -
also worth noting that
find_element_by_class_name()
can't take multiple classes: stackoverflow.com/questions/37771604/…ernie– ernie2021年03月10日 21:46:06 +00:00Commented Mar 10, 2021 at 21:46
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
driver.find_element_by_css_selector(".col.text-undefined").text
-
What would be the difference between this and pavel's answer?2021年03月15日 03:03:53 +00:00Commented Mar 15, 2021 at 3:03
-
Please add some explanation to the answer that might be helpful.IAmMilinPatel– IAmMilinPatel2021年03月15日 04:04:28 +00:00Commented Mar 15, 2021 at 4:04
-
Pavels answer is correct, no differencevitaliis– vitaliis2021年03月15日 11:49:02 +00:00Commented Mar 15, 2021 at 11:49
default