Page load strategy for Chrome driver (updated to Selenium v3.12.0)

I am using a Chrome browser to test WebApp.

Sometimes pages load after a very long time. I needed to stop the download or limit the download time.

At Firefox, I know about PAGE_LOAD_STRATEGY = "eager".

Is there something similar for chrome?

PS: it driver.manage().timeouts().pageLoadTimeout()works, but after that any call to Webdriver is called TimeOutException. I need to get the current page url after the download stops.

+9
source share
3 answers

ChromeDriver 77.0 ( Chrome 77) eager pageLoadStrategy.

1902: [Pri-2]


Webdriver:

, , , , .

Page Loading (, CSS, JS ..), pageLoadStrategy webdriver.

pageLoadStrategy :

  1. normal

    Selenium ( html- ).

  2. eager

    Selenium DOMContentLoaded ( HTML-).

  3. none

    Selenium , ( html-).

, Selenium , normal pageLoadStrategy.


pageLoadStrategy() DesiredCapabilities, ChromeOptions :

  • DesiredCapabilities :

    package demo; //replace by your own package name
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    public class A_Chrome_DCap_Options {
    
        public static void main(String[] args) {
    
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            DesiredCapabilities dcap = new DesiredCapabilities();
            dcap.setCapability("pageLoadStrategy", "normal");
            ChromeOptions opt = new ChromeOptions();
            opt.merge(dcap);
            WebDriver driver = new ChromeDriver(opt);
            driver.get("https://www.google.com/");
            System.out.println(driver.getTitle());
            driver.quit();
        }
    }
    
  • ChromeOptions :

    package demo; //replace by your own package name
    
    import org.openqa.selenium.PageLoadStrategy;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    
    
    public class A_Chrome_Options_test {
    
        public static void main(String[] args) {
    
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            ChromeOptions opt = new ChromeOptions();
            opt.setPageLoadStrategy(PageLoadStrategy.NORMAL);
            WebDriver driver = new ChromeDriver(opt);
            driver.get("https://www.google.com/");
            System.out.println(driver.getTitle());
            driver.quit();
        }
    }
    

: pageLoadStrategy normal, eager none WebDriver W3C Editor pageLoadStrategy eager - WIP () ChromeDriver. Chromedriver Selenium Python


:

+15

#, PageLoadStrategy.Eager, , Chrome, WebDriverWait. PageLoadStrategy none, :

new WebDriverWait(_driver, TimeSpan.FromSeconds(20))
    .Until(d =>
    {
      var result = ((IJavaScriptExecutor) d).ExecuteScript("return document.readyState");
      return result.Equals("interactive") || result.Equals("complete");
    });

chrome , TimeSpan 20 . , 20 ,

0

. .

:

WebDriver driver = new FirefoxDriver();
String startURL = //a starting url;
String currentURL = null;
WebDriverWait wait = new WebDriverWait(driver, 10);

foo(driver,startURL);

/* go to next page */
if(driver.findElement(By.xpath("//*[@id='someID']")).isDisplayed()){
    String previousURL = driver.getCurrentUrl();
    driver.findElement(By.xpath("//*[@id='someID']")).click();  
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    ExpectedCondition e = new ExpectedCondition<Boolean>() {
          public Boolean apply(WebDriver d) {
            return (d.getCurrentUrl() != previousURL);
          }
        };

    wait.until(e);
    currentURL = driver.getCurrentUrl();
    System.out.println(currentURL);
}   

,

-1

Source: https://habr.com/ru/post/1016927/


All Articles