Python Selenium CSS Selector by Span get_attribute

纵饮孤独 提交于 2021-02-08 03:30:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!