7

Here is the link I'm trying to click:

<a href="#" onclick="OpenAddKeywords();return false;" id="btnAddKeywords">Add Keywords</a>

I tried a few options(listed below) but they didn't work; any ideas?

  1. self.br.find_element_by_xpath("//*[@id='btnAddKeywords']").click()
  2. self.br.execute_script("OpenAddKeywords();return false;")

This is the error I've got for execute_script:

Message: u'Error Message => \'Can\'t find variable: OpenAddKeywords\'\n caused by Request =>

And this is the one that I've got for xpath:

Message: u'Error Message => \'Unable to find element with xpath \'//*[@id=\'btnAddKeywords\']\'\'\n caused by Request =>

6
  • How exactly they didn't work? Commented Jul 5, 2013 at 23:49
  • 2
    Did you try self.br.find_element_by_id('btnAddKeywords').click()? If that's not working, it's that you may not be on the page you think you are. Commented Jul 6, 2013 at 17:09
  • 1
    I have the same problem, you can also track my thread to find a solution. Commented Nov 5, 2013 at 7:19
  • 1
    I have solved the problem; see the answer. Commented Nov 5, 2013 at 10:15
  • 1
    @rozkosz, I'm really happy about that. I've posted it. Commented Dec 8, 2013 at 14:15

2 Answers 2

5

As I mentioned in my own question here, the problem would be solved by means of ActionChains class; a brief code is here:

el = driver.find_element_by_id("someid")
webdriver.ActionChains(driver).move_to_element(el).click(el).perform()

The main problem is that in some cases, specially when you have a some javascript codes in your page, the DOM would change and the element you've found before will be staled. 'ActionChains' would keep it alive to perform actions on.

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

1 Comment

@Mark My problem was very similar to yours and Zeinab's solution worked for me
3

You can try to use xpath like below. It is working for me because i have used last project.

driver.find_element_by_xpath("xpath").click()

Please try it...

1 Comment

Actually @Mark tried this and mentioned the result in the question; please read the question carefully and then answer. :)

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.