2

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?

2
  • Why the selector is different in the second case. Should not it be span[data-bind='calc']?.. Commented Jul 27, 2015 at 19:11
  • I am not sure if the selector is correct, I have been trying multiple things. The HTML is <span data-bind="text: calc"> … </span>, and the unique selector is .table > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(3) > span:nth-child(1). I don't know if CSS is even the best type of selector to use. Commented Jul 27, 2015 at 19:26

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This does not work with the first attempt, because I was having a timing issue and a selector issue. Changing the selector to get all span tags works perfectly in the second attempt though. Thanks @alecxe

Your Answer

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.