【问题标题】:Why Actions class not compatible with Firefox browser为什么 Actions 类与 Firefox 浏览器不兼容
【发布时间】:2019-01-20 06:39:04
【问题描述】:

我的配置:

selenium v 3.13.0 
geckodriver 0.21.0
Firefox version 61.0.1

我的应用程序中有以下类型的菜单,我必须将鼠标悬停在类别上,然后必须选择产品:

我正在使用 Actions 类来执行操作。使用下面的代码

@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 类别并从Weight Loss 类别中选择产品。我正在挠头寻找如何使该浏览器兼容的替代方法。

我尝试过显式/隐式/硬编码等待,但没有成功。我可以实现悬停并选择子菜单的 Action 类的任何替代方案。

【问题讨论】:

    标签: java selenium firefox geckodriver qaf


    【解决方案1】:

    我为 Firefox 添加了示例:

    public class Test {
        public static void main(String[] args) throws InterruptedException {
            WebDriver driver = new FirefoxDriver();
            driver.get("https://stackoverflow.com/questions/51823909/why-actions-class-not-compatible-with-firefox-browser");
            Thread.sleep(5000);
            Actions actions = new Actions(driver);
            actions.moveToElement(driver.findElement(By.cssSelector("#question-header > div > a"))).pause(3).click().perform();
        }
    }
    

    它有效。更详细地查看您的代码。尝试调试它。

    【讨论】:

    • 感谢您的回复。但它没有用。尽管我的脚本对于其他一些菜单选择工作正常。但对于少数选定的测试用例失败。我已经检查过它们,但没有发现导致失败的特殊情况。
    【解决方案2】:

    用下面的代码段替换我的代码后,开始为我工作。

    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();
    

    似乎在同一步骤中构建所有操作会导致问题。

    【讨论】:

      猜你喜欢
      • 2021-11-06
      • 2013-08-27
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-19
      • 1970-01-01
      相关资源
      最近更新 更多