5

在使用黄瓜框架执行编写 n selenium 的自动化脚本时,我得到以下异常

org.openqa.selenium.WebDriverException: 
    unknown error: Cannot read property 'defaultView' of undefined

以前在 spring 19 之前发布通过的脚本。在 spring 19 之后脚本失败并显示 ablve 异常

public void waitForElementToBeDisplayed(WebElement element) {
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    LOGGER.info("element is " +element);
    LOGGER.info(String.format("Waiting for WebElement '%s' to be displayed", element.toString().replaceAll(".*-> ", "").replace("]", "")));
    element = new WebDriverWait(driver, 40).until(ExpectedConditions.visibilityOf(element));
    Assert.assertTrue(element.isDisplayed());
}
4

1 回答 1

5

我有类似的异常点击事件。所以我使用了一种解决方法。我等待元素可点击,然后尝试用js点击它。

wait.until(ExpectedConditions.elementToBeClickable(STORE_ADMINISTRATION_LOCATOR));
// driver.findElement(STORE_ADMINISTRATION_LOCATOR).click(); <== this line returns
// WebDriverException: unknown error: Cannot read property 'defaultView' of undefined 

// replaced with
WebElement element = driver.findElement(STORE_ADMINISTRATION_LOCATOR);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
于 2019-06-12T20:31:58.103 回答