为什么 Actions class 与 Firefox 浏览器不兼容
Why Actions class not compatible with Firefox browser
我的配置:
selenium v 3.13.0
geckodriver 0.21.0
Firefox version 61.0.1
我的应用程序中有以下类型的菜单,我必须将鼠标悬停在类别上,然后才能选择产品:
我正在使用 Actions class 来执行操作。使用以下代码
@QAFTestStep(stepName = "navigateToCategoryProduct", description = "navigate to product name {0} under product category {1}")
public void navigateToCategoryProduct(String product, String category)
throws InterruptedException {
new Actions(getDriver()).moveToElement(getCategory(category)).pause(500)
.moveToElement(getProduct(category, product)).click().build().perform();
}
public QAFWebElement getCategory(String category) {
return new QAFExtendedWebElement(String.format(ConfigurationManager.getBundle()
.getString("header.navigation.category.link"), category));
}
public QAFWebElement getProduct(String category, String product) {
return new QAFExtendedWebElement(String.format(ConfigurationManager.getBundle()
.getString("header.navigation.product.link"), category, product));
}
因此 Chrome(使用 v68.0)一切顺利。但是,虽然在 Firefox 中使用相同的脚本,但它悬停在 Food
类别和 selecting 来自 Weight Loss
类别的产品。我绞尽脑汁想找到一个替代方法,我该如何使这个浏览器兼容。
我试过 explicit/implicit/hard 编码等待,但没有成功。我可以实现悬停和 select 子菜单的任何替代操作 class。
我已经为 Firefox 添加了示例:
public class Test {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("");
Thread.sleep(5000);
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.cssSelector("#question-header > div > a"))).pause(3).click().perform();
}
}
并且有效。更详细地查看您的代码。尝试调试它。
用下面的代码段替换我的代码后,开始为我工作。
Actions action = new Actions(getDriver());
action.moveToElement(getCategory(category)).build().perform();
waitForPresent(String.format(ConfigurationManager.getBundle().getString("header.navigation.product.link"), category, product));
getProduct(category, product).click();
似乎在同一步骤中构建所有操作导致了问题。
我的配置:
selenium v 3.13.0 geckodriver 0.21.0 Firefox version 61.0.1
我的应用程序中有以下类型的菜单,我必须将鼠标悬停在类别上,然后才能选择产品:
我正在使用 Actions class 来执行操作。使用以下代码
@QAFTestStep(stepName = "navigateToCategoryProduct", description = "navigate to product name {0} under product category {1}")
public void navigateToCategoryProduct(String product, String category)
throws InterruptedException {
new Actions(getDriver()).moveToElement(getCategory(category)).pause(500)
.moveToElement(getProduct(category, product)).click().build().perform();
}
public QAFWebElement getCategory(String category) {
return new QAFExtendedWebElement(String.format(ConfigurationManager.getBundle()
.getString("header.navigation.category.link"), category));
}
public QAFWebElement getProduct(String category, String product) {
return new QAFExtendedWebElement(String.format(ConfigurationManager.getBundle()
.getString("header.navigation.product.link"), category, product));
}
因此 Chrome(使用 v68.0)一切顺利。但是,虽然在 Firefox 中使用相同的脚本,但它悬停在 Food
类别和 selecting 来自 Weight Loss
类别的产品。我绞尽脑汁想找到一个替代方法,我该如何使这个浏览器兼容。
我试过 explicit/implicit/hard 编码等待,但没有成功。我可以实现悬停和 select 子菜单的任何替代操作 class。
我已经为 Firefox 添加了示例:
public class Test {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("");
Thread.sleep(5000);
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.cssSelector("#question-header > div > a"))).pause(3).click().perform();
}
}
并且有效。更详细地查看您的代码。尝试调试它。
用下面的代码段替换我的代码后,开始为我工作。
Actions action = new Actions(getDriver());
action.moveToElement(getCategory(category)).build().perform();
waitForPresent(String.format(ConfigurationManager.getBundle().getString("header.navigation.product.link"), category, product));
getProduct(category, product).click();
似乎在同一步骤中构建所有操作导致了问题。