首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法设置PageLoad of ChromeDriver实例

无法设置PageLoad of ChromeDriver实例
EN

Stack Overflow用户
提问于 2017-07-03 13:40:28
回答 2查看 1.7K关注 0票数 9

长期潜伏在这里,现在是我的第一个真正的帖子的时候了。我目前正在为在.NET中使用Selenium的应用程序开发一个跨浏览器测试。

http://www.guru99.com/cross-browser-testing-using-selenium.html之后,我实现了以下内容:

代码语言:javascript
复制
[SetUpFixture]
public class TestSetup()
{
    public static IWebDriver driver;
    ...

    [OneTimeSetUp]
    public void GlobalSetup()
    {
        if(browserToTest.Equals("Firefox"))
        {
              driver = new FirefoxDriver();
        }
        else if(browserToTest.Equals("Chrome"))
        {
              driver = new ChromeDriver();
        }

        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10.00);
        driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(10.00);

        // navigate to url, login, etc. pp
    }
}

在"Firefox“的例子中,一切都很好。与教程相反的"Chrome“案例给了我这个错误:

OneTimeSetUp: System.NotImplementedException :驱动程序实例必须符合W3C规范以支持获取超时值.

我正在使用:

  • Firefox v54.0
  • Chrome v59.0.3071.115
  • Selenium.WebDriver v3.4.0
  • Selenium.Firefox.WebDriver v0.17.0
  • Selenium.WebDriver.ChromeDriver v2.30.0.1

我可以为chrome设置ImplicitWait和PageLoad,还是只为火狐实现?

EN

回答 2

Stack Overflow用户

发布于 2019-10-10 07:45:30

你能试一下吗?

代码语言:javascript
复制
driver.manage().timeouts().implicitlyWait(10,timeunit.seconds)
driver.manage().timeouts().pageLoadTimeout(10,timeunit.seconds)

这是与硒3

票数 0
EN

Stack Overflow用户

发布于 2021-04-18 21:51:48

我使用了在chrome和firefox中都适用于我的代码。PageObject是我的类,waitPageToLoad是我的方法。

代码语言:javascript
复制
public class PageObject {
    protected Logger log = LogManager.getLogger(this.getClass().getName());
    protected WebDriver driver;
    protected WebDriverWait wait;

  public WebDriver getDriver() {
    log.debug("obtaining the driver object for current thread");
    return driver;
} 
 public WebDriverWait getWait() {
    log.debug("obtaining the wait object for current thread");
    return wait;
}
 public void initialise(Object obj) {
    PageFactory.initElements(getDriver(), obj);
}

 public PageObject waitPageToLoad() {
        domLoaded();
        jqueryLoaded();
        return this;
    }

 public void domLoaded() {
        log.debug("checking that the DOM is loaded");
        final JavascriptExecutor js = (JavascriptExecutor) getDriver();
        Boolean domReady = js.executeScript("return document.readyState").equals("complete");

        if (!domReady) {
            getWait().until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver d) {
                    return (js.executeScript("return document.readyState").equals("complete"));
                }
            });
        }
    }

  private void jqueryLoaded() {
        log.debug("checking that any JQuery operations complete");
        final JavascriptExecutor js = (JavascriptExecutor) getDriver();

        if ((Boolean) js.executeScript("return typeof jQuery != 'undefined'")) {
            boolean jqueryReady = (Boolean) js.executeScript("return jQuery.active==0");

            if (!jqueryReady) {
                getWait().until(new ExpectedCondition<Boolean>() {
                    public Boolean apply(WebDriver d) {
                        return (Boolean) js.executeScript("return window.jQuery.active === 0");
                    }
                });
            }
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44887069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档