【问题标题】:selenium firefox modal displays as a pop-up window, not a modalselenium firefox 模态显示为弹出窗口,而不是模态
【发布时间】:2015-06-03 19:13:28
【问题描述】:

我正在尝试使用 Selenium 在包含多个页面的网站上测试表单。根据所选择的选项,假设某些页面上会出现模式。目前,我无法让 Selenium 与 Fireforx 和模态一起正常工作。 Chrome 按预期运行,我没有打扰 I.E.还没有。

  • 当我使用 Firefox 手动浏览页面时,一切正常。
  • 当我运行我的 Selenium 脚本时,模态显示就像一个 Windows 弹出窗口,而不是一个模态。

我正在使用 driver.switchTo().alert().accept(); 来处理模态,我遇到的第一个模态会关闭,但是一旦我进入下一页Selenium 代码无法找到页面上的任何元素。

这是我用来点击按钮的代码:

public void pushButton(String[] values) {
    System.out.println("\t Click (" + values[1] + ")");
    setLocator(values[0], values[1]);

    try {
        clickWhenReady(locator).click();
    } catch (Exception e) {
        System.out.println("Could not find id or xpath value: " + values[1]);
        e.printStackTrace();
    }
}

private void setLocator(String byType, String value) {
    if(byType.toUpperCase().equals("ID")) {
        locator= By.id(value);
    } else if(byType.toUpperCase().equals("XPATH")){
        locator= By.xpath(value);
    }
}

private WebElement whenReady(By locator){
    WebElement element = (new WebDriverWait(driver, 30))
            .until(ExpectedConditions.presenceOfElementLocated(locator));
    return element;
}

private WebElement clickWhenReady(By locator){
    WebElement element = (new WebDriverWait(driver, 30))
            .until(ExpectedConditions.elementToBeClickable(locator));
    return element;
}

【问题讨论】:

    标签: java selenium modal-dialog


    【解决方案1】:

    首先,modals 不是alerts,所以driver.switchTo().alert().accept(); 可能不会给你买任何东西。

    真正的问题可能是模态框需要更长的时间才能淡出并阻止Selenium 与页面交互。您最好的选择是尝试等待模态从 dom 中完全消失,然后尝试与元素进行交互。为此,您可以使用invisibilityOfElementLocatedExpectedConditions 或类似机制。见this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      相关资源
      最近更新 更多