2

I'm trying to create a method that wait for the page to load by javascript, but I'm having an error. probably I'm not using the method correctly.

public static void WaitForLoad(this IWebDriver driver, int timeoutSec = 15)
    {
        WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, timeoutSec));
        wait.Until(wd => wd.ExecuteJavaScript("return document.readyState") == "complete");
    }

The error is:

The type arguments for method 'WebdriverExtensions.ExecuteJavaScript<T>(IWerbDriver,string,params object[]' cannot be inferred from the usage.Try specifying the type arguments explicity)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
JumpIntoTheWater
  • 1,306
  • 2
  • 19
  • 46

1 Answers1

2

In the WaitForLoad(...) function you are checking for ("return document.readyState") == "complete"

Practically, the call to the function WaitForLoad(...) is purely an overload and have no real effect. That is because Selenium DLL/JARS/Modules are designed in such a way that the webdriver executes the next line of code only when the Browser which you are using sends document.readyState == "complete" to the WebDriver.

In your case instead of validating document.readyState == "complete" it will be much more effective if we wait i.e. induce ExplicitWait for the next WebElement with which we intend to interact with appropriate clause from either ElementIsVisible(By), ElementToBeClickable(By), ElementToBeClickable(IWebElement), ElementToBeSelected(IWebElement, Boolean), etc.

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