-1

I have an instance whereby the page I'm navigating to never fully loads in the test environments although all GUI elements are visible, this is as a result of a keepalive.php script which keeps the connection open to Google Analytics and other analytical scripts within the code awaiting the sending and receiving of information. As we don't collect the statistics within the network, the script never finishes and the page never fully loads.

When navigating to the page manually, pressing Escape stops the script from running and loads the page therefore I tried using the Selenium Actions:

Actions action = new Actions(driver);
action.SendKeys(Keys.Escape);

However, I believe this code is never reached, as Selenium is waiting for the page to fully load before executing any further lines of code.

Unfortunately removing or altering the keepalive.php and google analytics code within our test environments is not a viable option, rather our automation suite must work around this.

MatthewThomas.dev
  • 1,045
  • 10
  • 24

2 Answers2

0

You can set a PageLoadTimout. With this, Selenium would throw an error when it cant load the site in the specified time, which you could catch and continue. Not very elegant, sadly.

driver.Manage().Timeouts().SetPageLoadTimeout(timespan)

Taken from Selenium WebDriver - How to set Page Load Timeout using C#

According to Page Load Timeout - Selenium Webdriver using C# it is possible that not every Browser supports the timeout.

Community
  • 1
  • 1
Sosian
  • 622
  • 11
  • 28
0

Set Implicitly Wait to zero.

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));

and wait for elements by explicit wait

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
    {
        return d.FindElement(By.Id("someDynamicElement"));
    });
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43