问题
I have already accessed a webpage, populated text boxes and drop downs with required parameters, and submitted (button click) this information so the webpage can perform a calculation. I am trying to access the results (value of text). Results should be a list of calculations listed least to greatest, and I only want the lowest value. I am not sure if I am having a timing issue or a CSS Selector issue.
I have tried:
e = driver.find_elements_by_css_selector("span[data-bind='calc']")
new = e[0].text
print(new)
Error: IndexError: list index out of range
I wanted to make sure the data table was being completely populated before I tried to access it's calculated elements, and I have also tried:
output_by_css = WebDriverWait(driver, 10).until(
lambda driver : driver.find_elements_by_css_selector('span.calc')
)
for output in (output_by_css):
print(output.text)
Error: raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Can someone please help me determine if this is an issue with the CSS Selector by span or if it's a timing issue, or something else I have not yet thought of? How can I fix it?
回答1:
You can try applying the following selector:
driver.find_elements_by_css_selector('span[data-bind*=calc]')
Here we are getting all the span
tags having data-bind
attribute having "calc" inside the value.
来源:https://stackoverflow.com/questions/31661145/python-selenium-css-selector-by-span-get-attribute