7

I want to click a button which is visible after hovering. Its html is:

<span class="info"></span> 

I used this code:

import selenium.webdriver as webdriver from selenium.webdriver.common.action_chains import ActionChains url = "http://example.com" driver = webdriver.Firefox() driver.get(url) element = driver.find_element_by_class_name("info") hov = ActionChains(driver).move_to_element(element) hov.perform() element.click() 

It's not working though. I got a an error connected with the last line of code element.click():

selenium.common.exceptions.ElementNotVisibleException: Message: \ u'Element is not currently visible and so may not be interacted with' 

Any suggestions please?

1
  • The errors are what exactly?
    – Arran
    CommentedMay 30, 2013 at 8:16

1 Answer 1

11

I bet you should wait for the element until it becomes visible.

Three options:

  • call time.sleep(n)
  • use WebDriverWait like it's suggested here and here

I'd go with the second option.

UPD:

On this particular site hovering via selenium didn't work at all, so the only option was to click on the button using js via execute_script:

driver.execute_script('$("span.info").click();') 

Hope that helps.

5
  • Thanks for suggestions but I've tried time.sleep actually and it seems it's not the case.
    – nutship
    CommentedMay 30, 2013 at 8:45
  • Ok, WebDriverWait should work, let me know if you'll have problems with it.
    – alecxe
    CommentedMay 30, 2013 at 8:49
  • Sorry for late answer but needed to read your links through. I still think my issue differs as the element/button in my case is visible/accessible all the time. So I can hover over it instantly as the page loads. There is no ajax/js code execution in between. I'm just unable to correctly localize the elements either with find_element_by or xpath.
    – nutship
    CommentedMay 30, 2013 at 10:03
  • got it, could you provide the link to the page, so I can find a workaround for you?
    – alecxe
    CommentedMay 30, 2013 at 10:09
  • I'd love to. For 'security' reasons I think I'm better off not posting it. Can we possibly contact via email?
    – nutship
    CommentedMay 30, 2013 at 10:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.