运行 Firefox 中的 selenium webdriver 测试不工作
running selenium webdriver test in firefox is not working
我正在尝试单击 when 页面上的子菜单项。我使用以下代码来执行操作。
WebElement mainMenu = driver.findElement(By.xpath(".//*[@class='main-menu']"))
WebElement subMenu = driver.findElement(By.xpath(".//*[@class='sub-menu-item2']"))
mainMenu.click();
actions.moveToElement(mainMenu).build().perform();
subMenu.click();
此代码在使用 Chrome 浏览器时运行良好,但不适用于 Firefox。
通过阅读几篇文章,我了解到 geckodriver 尚未实施操作“https://github.com/mozilla/geckodriver/issues/233”,这证明当 运行 我的测试是 firefox 时,我的代码将无法工作。
我没有使用 Actions,而是使用了 JavaScriptExecutor,它对我来说工作得很好,这是我使用的命令。
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", mainMenu);
subMenu.click();
这在 Chrome 和 Firefox 浏览器上都运行良好。
我正在尝试单击 when 页面上的子菜单项。我使用以下代码来执行操作。
WebElement mainMenu = driver.findElement(By.xpath(".//*[@class='main-menu']"))
WebElement subMenu = driver.findElement(By.xpath(".//*[@class='sub-menu-item2']"))
mainMenu.click();
actions.moveToElement(mainMenu).build().perform();
subMenu.click();
此代码在使用 Chrome 浏览器时运行良好,但不适用于 Firefox。
通过阅读几篇文章,我了解到 geckodriver 尚未实施操作“https://github.com/mozilla/geckodriver/issues/233”,这证明当 运行 我的测试是 firefox 时,我的代码将无法工作。
我没有使用 Actions,而是使用了 JavaScriptExecutor,它对我来说工作得很好,这是我使用的命令。
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", mainMenu);
subMenu.click();
这在 Chrome 和 Firefox 浏览器上都运行良好。