且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Firefox 19中使用Selenium WebDriver进行鼠标悬停?

更新时间:2023-11-29 21:10:04

使用actions对象,您应首先移动菜单标题,然后移动到弹出菜单项并单击它。不要忘记最后调用 actions.perform()。以下是一些示例Java代码:

With the actions object you should first move the menu title, and then move to the popup menu item and click it. Don't forget to call actions.perform() at the end. Here's some sample Java code:

Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.linkText("Menu heading"));
actions.moveToElement(menuHoverLink);

WebElement subLink = driver.findElement(By.cssSelector("#headerMenu .subLink"));
actions.moveToElement(subLink);
actions.click();
actions.perform();