【发布时间】:2013-08-15 04:15:21
【问题描述】:
在无头模式下使用 selenium web-driver API,我试图在菜单项上执行鼠标悬停;以便显示所有子菜单项。之后,我单击其中一个子菜单项。以下是sn -p的代码:
Actions actions = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, 20);
//Waiting for menu item to be clickable
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(menu_item)));
WebElement firstLink = driver.findElement(By.cssSelector(menu_item));
//Hovering over the menu item
actions.moveToElement(firstLink).build().perform();
//Waiting for the sub-menu item to be clickable - ERRORS OUT HERE
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(submenu_item)));
//Getting the second link
WebElement secondLink = driver.findElement(By.cssSelector(submenu_item));
//Click on sub menu
actions.moveToElement(secondLink).click().build().perform();
但是,测试超时,说找不到子菜单项。
我已验证上述操作与 Firefox 驱动程序完美兼容。 此外,css 选择器是正确的。
PhantomJs 和鼠标悬停操作是否存在任何已知问题 - 这可能解释了为什么代码不能使用 PhantomJs 驱动程序运行。如果是这样,是否有任何解决方法。
另外,是否有更好的方法来对 API 进行排序以模拟鼠标悬停然后单击操作?
(注意:我也尝试链接How to perform mouseover function in Selenium WebDriver using Java? 中提到的操作,但没有帮助)
【问题讨论】:
-
我认为 PhantomJS 还不支持这个。您找到解决方法了吗?
-
简单回答:Javascript 没有被执行!
标签: java selenium-webdriver phantomjs