c# - 等待页面加载

标签 c# selenium selenium-webdriver

我正在尝试创建一个等待 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/

相关文章:

c# - Selenium ChromeDriver 管理超时

java - 使用 Selenium 在 Chrome 上处理 "Your connection to this site is not private"弹出窗口

selenium-webdriver - Selendroid Android 测试

java - 如何通过标签名称检索多个标签内的元素以进行selenium自动化测试

java - 使用 Selenium 独立服务器 3.9.1 在 Eclipse Photon 中导入时出现 "The import org cannot be resolved"错误

c# - 如何创建包含多个实体(作为单独的参数传递)的 "Include"重载?

java - 有什么方法可以让我们返回尝试阻止捕获

c# - 从数据集导出到制表符分隔的文件

c# - 错误 CS0103 : The name does not exist in the current context when debugging referenced project

c# - 如何检查数据库中是否存在记录 - 最快的方法