【问题标题】:org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'defaultView' of undefinedorg.openqa.selenium.WebDriverException:未知错误:无法读取未定义的属性“defaultView”
【发布时间】:2019-02-11 10:47:38
【问题描述】:

在使用黄瓜框架执行 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());
}

【问题讨论】:

  • 嗨@delframe,你能分享错误日志吗?对于哪个输入,您究竟在哪一行和什么错误?
  • 你找到解决办法了吗?

标签: selenium salesforce undefined uncaught-exception defaultview


【解决方案1】:

我有类似的异常点击事件。所以我使用了一种解决方法。 我等待元素可点击,然后尝试用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);

【讨论】:

  • 这么简单的操作需要这样的解决方法真是太疯狂了,但你的代码对我有用。感谢您发布此消息!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-24
  • 1970-01-01
  • 2020-10-15
  • 2018-04-29
相关资源
最近更新 更多