How to code mouse hover with Selenium Webdriver

I was trying to code for mousehover
and i actually followed someone’s code and to me
its not working

How to code mouse hover with Selenium Webdriver

also the I can’t really find the element id for
How to code mouse hover with Selenium Webdriver
for this part
there is no id specified

Add Comment
3 Answer(s)

To use ID it has to be present in the element’s html. In the image shown, highlighted element, there is no id. The only valid attribute is class. I would suggest you find this element using Xpath. Also the correct syntax is
driver.findElement(“HM_Item2_4″)); you dont  have to specify the id= in it. However in  this case I would suggest use Xpath.

You can take a look at the tutorial here


Virender Singh Professor Answered on July 14, 2015.
Add Comment

Let me show you the code for mouse hover

//navigate index page

//hover electronics tab
WebElement moveonmenu=driver.findElement(By.xpath(“.//*[@id=’fk-mainhead-id’]/div[2]/div/div/ul/li[1]/a/span”));
Actions actions=new Actions(driver);
try {
} catch (InterruptedException e) {
//hover and click Mi from Mobiles
WebElement mi=driver.findElement(By.xpath(“.//*[@id=’menu-electronics-tab-0-content’]/ul[1]/li[5]/a”));

If you have any question just ask

Janani Train Answered on July 14, 2015.
Add Comment

you can also do it by following

Actions act=new Actions(driver);

where XPATH is the xpath of the element you want to hover the mouse to.
Hope this helps.

Namit Default Answered on July 15, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.