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?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
April
  • 89
  • 7
  • Why the selector is different in the second case. Should not it be `span[data-bind='calc']`?.. – alecxe Jul 27 '15 at 19:11
  • I am not sure if the selector is correct, I have been trying multiple things. The HTML is , 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. – April Jul 27 '15 at 19:26

1 Answers1

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.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 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 – April Jul 27 '15 at 19:43