我正在尝试创建一个等待 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<T>(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 的设计方式是,仅当您使用的浏览器将 webdriver
发送到WebDriver。
在您的情况下,如果我们等待,而不是验证 document.readyState == "complete"
,将会更有效,即为我们使用的下一个WebElement引入ExplicitWait打算与 document.readyState == "complete"
、 ElementIsVisible(By)
、 ElementToBeClickable(By)
、 ElementToBeClickable(IWebElement)
等中的适当子句进行交互。
关于c# - 等待页面加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47130366/