0

I am using Selenium Web driver version 2.48.2.

My issue is that I want to wait for the very last url to be loaded and then take my screen shot and close the browser and driver.

So if I debug the session, I can see all my methods being called immediately, not waiting for the browser to load up, this is a problem because If I have my Quit() method on the last line of code the browser closes immediately, and doesn't run through each step in time.

If I remove the Quit() method, the browser runs through all my scenarios as expected.

So is there a way to have the driver wait until the browser is finished actioning all my steps?

Any help is much appreciated.

Mark Beattie
  • 175
  • 1
  • 13

1 Answers1

0

It really depends on what is happening. The best way is to wait for an element to appear on the screen using an explicit wait http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

IWebDriver driver = new FirefoxDriver();
    driver.Url = "http://somedomain/url_that_delays_loading";
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
    {
        return d.FindElement(By.Id("someDynamicElement"));
    });

If that is not possible, you might try injecting javascript into the page with a

setTimeout(functionThatAddsAnElementToTheDom,1);

This will run once your other process has completed and you can test for the new element using Wait.Until()

Dave Bush
  • 2,382
  • 15
  • 12