简体   繁体   中英

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM