I'm trying to write a script to test an option of a website, this option enables users to edit their own message and so it's represented by a pencil icon which has the xpath:


The problem is that icon appears only if users hover their own message with their mouse. So for Selenium it's not a visible element and I have an Exception.

I have another exception now, and I think it's linked to the hov.perform()

This is the message:

Traceback (most recent call last):
File "private_discussion_script.py", line 50, in test_script_shift
hov = ActionChains(driver).move_to_element(element).perform()
File "C:\PYTHON27\lib\site-packages\selenium-3.0.0b3-py2.7.egg\selenium\webdriver\common\action_chains.py", line 74, in perform
File "C:\PYTHON27\lib\site-packages\selenium-3.0.0b3-py2.7.egg\selenium\webdriver\common\action_chains.py", line 225, in <lambda>
Command.MOVE_TO, {'element': to_element.id}))
File "C:\PYTHON27\lib\site-packages\selenium-3.0.0b3-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 236, in execute
File "C:\PYTHON27\lib\site-packages\selenium-3.0.0b3-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: POST /session/80574c31-b05c-4bb7-8cb2-053ebe4eeae5/moveto did not match a known command`

You need to perform a mouseover action onto this element to make it visible first.

from selenium.webdriver.common.action_chains import ActionChains

def hover(self):
    browser = webdriver_connection.connection
    element = browser.find_element_by_xpath(your xpath)
    hov = ActionChains(browser).move_to_element(element)
| improve this answer | |
  • When I perform element = driver.find_element_by_xpath("//*[@id='content']/div[2]/div/div[2]/div/div[2]/div[1]/div/div[26]/div[3]/div[1]/span[1]/button[1]") – LeBrequin Oct 15 '16 at 5:51
  • Sorry, when I perform this line, I have the NoSuchElement exception. – LeBrequin Oct 15 '16 at 5:52
  • can you please post the HTML here? – Yu Zhang Oct 15 '16 at 6:07
  • You're getting a no such element exception because probably the hoverover takes a little bit of time to load once you have reached that element. Once you go at this element, use some waiting to wait for 5-10 seconds – demouser123 Oct 15 '16 at 9:12
  • This is the HTML of this icon: – LeBrequin Oct 15 '16 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.