testing
testing

Reputation: 1796

How to mouse hover using javascript executor in selenium 2?

Currently working in Selenium WebDriver and using Java. I want to perform the action as mouse hover to the tab and it need to click the tab. Here in this code i can able to identify the element and it is opening the tab. But the problem is it is not mouse hovering and not clicking, it is directly opening the page.

 JavascriptExecutor executor = (JavascriptExecutor)driver;
         executor.executeScript("arguments[0].click();",                                                     
driver.findElement(By.id("ext-pr-backlog-evolution") ));

If i use the

WebElement menuHoverLink = driver.findElement(By.id("ext-pr-backlog-evolution"));
actions.moveToElement(menuHoverLink).click().perform();

It is not exactly finding the element and it is clicking some other tab. so i want to mouse hover in javascript executor.

Upvotes: 0

Views: 7448

Answers (1)

user3007675
user3007675

Reputation: 76

You can create a mouse event

document.createEvent('MouseEvents');

then assign a mouse hover to it

mouseEventObj.initEvent( 'mouseover', true, true );

and then dispatch it

element.dispatchEvent(mouseEventObj);

Upvotes: 3

Related Questions