0

We are running selenium and java automation project in chrome . it was running we want migrated to Micro soft Edge in that process we upgrade to Selenium 4.0 and java 1.8 edge 99. When we run the our project we are facing below error edge-browser

org.openqa.selenium.JavascriptException: javascript error: Function is not a constructor

Same code is working in chrome.

public void waitForLoad(long seconds) {
    ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver wd) {
            try {
                // this will tell if page is loaded
                JavascriptExecutor js = (JavascriptExecutor) getDriver();
                String windowState = js.executeScript("return document.readyState").toString();
                
                
                //String windowState = (String) ((JavascriptExecutor) wd).executeScript("return document.readyState;");
                log.debug("wait for window[" + wd.getWindowHandle() + "] sate:" + windowState);
                log.debug("WINDOW is generated >>>>>");
                return "complete".equals(windowState);
            } catch (Exception e) {
                
                log.debug("WINDOW is not loading>>>>>"+e);
                return false;
            }
        }
    };
    long waitSeconds = seconds;
    if(seconds<=0){
        waitSeconds = ENV.getPageloadTimeout();
    }
    WebDriverWait wait = new WebDriverWait(driver, waitSeconds);
    // wait for page complete
    log.debug("PageLoadState>>"+pageLoadCondition.toString());
    wait.until(pageLoadCondition);

We are facing issue in wait.until(pageLoadCondition); line in edge browser . Do any other way uset ExpectedConditio method

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
kedar
  • 11
  • 1

1 Answers1

0

As you migrated from lower versions of Selenium to Selenium v4.0, the new constructor for WebDriverWait is updated as:

public WebDriverWait​(WebDriver driver, java.time.Duration timeout)

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others. You can add more to the ignore list by calling ignoring(exceptions to add).

Parameters:
driver - The WebDriver instance to pass to the expected conditions
timeout - The timeout when an expectation is called

and the implementation is as follows:

WebDriverWait wait =  new WebDriverWait(testDriver, Duration.ofSeconds(1));

You need to change the defination of pageLoadCondition accordingly.


tl; dr

Class WebDriverWait

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352