等待页面加载

我正在尝试创建一个等待页面加载javascript ,但我遇到了错误。 可能我没有正确使用该方法。

 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 type arguments for method 'WebdriverExtensions.ExecuteJavaScript(IWerbDriver,string,params object[]' cannot be inferred from the usage.Try specifying the type arguments explicity) 

WaitForLoad(...)函数中,您正在检查("return document.readyState") == "complete"

实际上,对函数WaitForLoad(...)的调用纯粹是一个重载并且没有实际效果。 这是因为Selenium DLL / JARS / Modules的设计方式是只有当您使用的浏览器document.readyState == "complete"发送到WebDriver时, webdriver才会执行下一行代码。

在你的情况下,而不是validationdocument.readyState == "complete" ,如果我们等待,即为我们打算与ElementIsVisible(By)ElementToBeClickable(By)适当子句交互的下一个WebElement引入ExplicitWait将会更有效。 , ElementToBeClickable(IWebElement)ElementToBeSelected(IWebElement, Boolean)等。