Make Selenium Webdriver Stop Page loading, if the necessary element is already loaded?

I am creating a test and have some problems. Here is the script. I use the Selenium Web driver to fill out the form on page 1 and submit the form by clicking a button. Page2 starts loading ... but the problem is that the page uses Google Analytics codes, and sometimes the page stops loading forever.

Although the expected element is already present, the Selenium web driver does not work until the entire web page is fully loaded.

How to get Selenium to go to the next task or stop loading external javascript / css if the expected element is already present?

I tried to configure the following settings, but no luck.

driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

TEMPORARY RESOLUTION: scroll below to answer!

+6
source share
7 answers

So, I informed Selen about these issues. And a temporary workaround ... to bother with Firefox timeout settings. Basically, by default, Firefox waits about 250 seconds for each connection until it shuts down. You can check: config for details. I basically rolled it down so Firefox doesn't wait too long and Selenium can continue as if the page has already finished loading: P.

A similar configuration may exist for other browsers. I still think that Selenium should allow us to handle the pagetimeout exception. Make sure you add an asterisk to the error: http://code.google.com/p/selenium/issues/detail?id=6867&sort=-id&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary , therefore selenium corrects these problems.

 FirefoxBinary firefox = new FirefoxBinary(new File("/path/to/firefox.exe")); FirefoxProfile customProfile = new FirefoxProfile(); customProfile.setAcceptUntrustedCertificates(true); customProfile.setPreference("network.http.connection-timeout", 10); customProfile.setPreference("network.http.connection-retry-timeout", 10); driver = new FirefoxDriver(firefox, customProfile); driver.manage().deleteAllCookies(); 
+5
source

Give below approaches to the shot.

 driver.findElement(By.tagName("body")).sendKeys("Keys.ESCAPE"); 

or

 ((JavascriptExecutor) driver).executeScript("return window.stop"); 

Alternatively, you can also use WebDriverBackedSelenium, as shown in the snippet below, starting with Vincent Bouvier.

 //When creating a new browser: WebDriver driver = _initBrowser(); //Just returns firefox WebDriver WebDriverBackedSelenium backedSelenuium = new WebDriverBackedSelenium(driver,"about:blank"); //This code has to be put where a TimeOut is detected //I use ExecutorService and Future<?> Object void onTimeOut() { backedSelenuium.runScript("window.stop();"); } 

Source: https://sqa.stackexchange.com/a/6355

Source: fooobar.com/questions/320687 / ...

+4
source

After you have checked an element and know that it is present, you can either go to / load another page (if the following tasks are on another page), or if the tasks are on the same page (for example, you still do not need elements, which are not yet loaded), you can continue as usual - selenium will identify already loaded elements. This works for me when I work with feature rich pages.

0
source

Instead of using webdriver, click () to submit the form, use jsexecutor and click. Jsexecutor does not wait for the page to load, and you can perform other actions.

0
source

In accordance with the above scenario, I believe that it is better to use the wait wait command on the first page.

 WebDriverWait wait = new WebDriverWait(driver, 10); WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.id(>someid>))); 

Once the desired item is found on the first page, you can go to the second page.

-1
source

In accordance with the above scenario, I believe that it is better to use the wait wait command on the first page.

 WebDriverWait wait = new WebDriverWait(driver, 10); WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.id(>someid>))); 

Once the desired item is found on the first page, you can go to the second page.

-1
source

Use explicit / webdriver wait ----

  WebDriverWait wt=new WebDriverWait(driver, 20); wt.until(ExpectedConditions.elementToBeClickable(By.name("abc"))); 
-2
source

All Articles