简体   繁体   中英

mouse hover action in selenium WebDriver

I want to know how to do do mouse hover action in selenium Web Driver.

The mouse hover action need to perform on tab. It need to hover then it need to click the tab. How can i do this using JavaScript executor and java .

Javascript executor should be the last resort to perform any action with Selenium. Selenium provides an Action class using which you can perform mouse/keyboard actions. For your scenario,

Actions builder = new Actions(driver);   
Action hoverAndClick = builder.moveToElement(webElement).click(webElement).build();
hoverAndClick.perform();

Here is an example:

Actions act = new Actions(driver);

WebElement parentMenu = driver.findElement(By.xpath("Xpath"));
//Move to the element
act.moveToElement(parentMenu).build().perform()

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