2

I have a page that contains the following line of html

<td><span><a onClick="setSummaryClasses(3)">Reality</a></span></td>

Copied from the FF Source panel. I try to click the anchor with

driver.find_element_by_link_text('Reality').click()

and I get a

NoSuchElementException: Message: u'Unable to locate element: {"method":"link text","selector":"Reality"}'

What am I missing?

I have both

driver.set_script_timeout(10)
driver.implicitly_wait(10) # seconds

active.

1
  • What selenium driver are you using? Commented Apr 21, 2014 at 0:11

2 Answers 2

3
  1. Ensure the link isn't inside any kind of frames. Otherwise please use switch_to_frame first.

  2. When you match link text, bear in mind it does exact match, so if you have messy whitespaces, please try find_element_by_partial_link_text

    driver.find_element_by_partial_link_text('Reality').click()
    
  3. Changing locators might also be helpful.

    driver.find_element_by_css_selector("a[onClick='setSummaryClasses(3)']").click()
    
Sign up to request clarification or add additional context in comments.

1 Comment

And ensure the current window in Selenium is the window you think it is :).
1

Thanks to user1177636, I realised that, when a click opens a window, in the LIVE situation the new window becomes the current "top" window, while in Selenium it doesn't.

Therefore I needed to

driver.switch_to_window('Chat23')

before looking for the element.

Hope this helps somebody.

Comments

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.