Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set PageLoad of ChromeDriver instance

long time lurker here, now it's time for my first real post. I am currently developing a cross browser test for our application with Selenium in .NET.

Following http://www.guru99.com/cross-browser-testing-using-selenium.html, I implemented this:

[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
    }
}

In the "Firefox" case, everything works great. The "Chrome" case - in contrary to the tutorial - gives me this error:

OneTimeSetUp: System.NotImplementedException : Driver instance must comply with the W3C specification to support getting timeout values.

Im using:

  • 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

Can I set ImplicitWait and PageLoad for chrome, or is this only implemented for firefox?

like image 778
Felix Beifuß Avatar asked Jul 03 '17 13:07

Felix Beifuß


1 Answers

i used this code which worked for me in both chrome and firefox. PageObject is my class and waitPageToLoad is my method.

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");
                    }
                });
            }
        }
    }
}
like image 183
Sonali Das Avatar answered Oct 19 '22 18:10

Sonali Das