2

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:

"//*@id='content']/div[2]/div/div[2]/div/div[2]/div[1]/div/div[26]/div[3]/div[1]/span[1]/button[1]

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
action()
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
self.error_handler.check_response(response)
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`
Sandeep
3332 gold badges5 silver badges21 bronze badges
asked Oct 15, 2016 at 3:55

1 Answer 1

1

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)
 hov.perform()
answered Oct 15, 2016 at 4:06
6
  • 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]") Commented Oct 15, 2016 at 5:51
  • Sorry, when I perform this line, I have the NoSuchElement exception. Commented Oct 15, 2016 at 5:52
  • can you please post the HTML here? Commented Oct 15, 2016 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 Commented Oct 15, 2016 at 9:12
  • This is the HTML of this icon: Commented Oct 15, 2016 at 10:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.