Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

While executing automation scrits written n selenium using cucumber frame work iam getting the below exception

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

Previously befor spring 19 release the scripts where passed .After spring 19 scripts are failing and showing ablve exception

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());
}
like image 307
delframe Avatar asked Feb 11 '19 10:02

delframe


1 Answers

I had similar Exception on-click event. So I used a workaround. I wait for element to be clickable and then trying to click on it with 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);
like image 76
nassy Avatar answered Nov 10 '22 06:11

nassy