5

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());
}
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
delframe
  • 51
  • 1
  • 2

1 Answers1

5

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);
nassy
  • 201
  • 3
  • 5
  • It's crazy that such a simple operation requires a workaround like this, but your code worked for me. Thanks for posting this! – greglorious_85 Dec 16 '19 at 14:50