javaseleniumselenium-webdriverwebdriverpageloadtimeout

pageLoadTimeout in Selenium not working


I am using below code using selenium in Java. I am adding pageLoadTimeout of 4 seconds, however, the driver continues to wait till the complete page is loaded. Any help?

System.setProperty("webdriver.gecko.driver", System.getProperty("user.home") + "\\Desktop\\geckodriver.exe");

        FirefoxBinary b = new FirefoxBinary(new File(System.getProperty("user.home") + "\\desktop\\Mozilla Firefox\\firefox.exe"));
        FirefoxOptions options = new FirefoxOptions().setBinary(b);
        driver = new FirefoxDriver(options);
        //driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(4, TimeUnit.SECONDS);


        driver.get("https://www.booking.com/hotel/in/the-taj-mahal-palace-tower.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaGyIAQGYATG4AQbIAQzYAQHoAQH4AQKSAgF5qAID;sid=338ad58d8e83c71e6aa78c67a2996616;dest_id=-2092174;dest_type=city;dist=0;group_adults=2;hip_dst=1;hpos=1;room1=A%2CA;sb_price_type=total;srfid=ccd41231d2f37b82d695970f081412152a59586aX1;srpvid=c71751e539ea01ce;type=total;ucfs=1&#hotelTmpl");
List<WebElement> facilitySectionList = driver.findElements(By.className("facilitiesChecklistSection"));

Solution

  • The solution to your pageLoadTimeout issue would be to bump up your Selenium version to v3.5.0. Here is effective code block and the resulted org.openqa.selenium.TimeoutException: Timeout loading page after 2000ms of your own code in minimal lines:


    Catching the WebDriverException