selenium firefox模态显示为弹出窗口,而不是模态

时间:2015-06-03 19:13:29

标签: java selenium modal-dialog

我正在尝试使用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;
}

1 个答案:

答案 0 :(得分:0)

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

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

相关问题