How to use Enum PageLoadStrategy class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.Enum PageLoadStrategy

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package Camargo.Automacao.BDD.Utils;
2
3import io.github.bonigarcia.wdm.WebDriverManager;
4import org.junit.Assert;
5import org.openqa.selenium.PageLoadStrategy;
6import org.openqa.selenium.WebDriver;
7import org.openqa.selenium.chrome.ChromeDriver;
8import org.openqa.selenium.chrome.ChromeOptions;
9import org.openqa.selenium.firefox.FirefoxDriver;
10import org.openqa.selenium.firefox.FirefoxOptions;
11import org.openqa.selenium.ie.InternetExplorerDriver;
12import org.openqa.selenium.ie.InternetExplorerOptions;
13
14
15public class WebDriverFactory {
16	
17	static WebDriver driver;
18
19	public enum Navegador {
20
21		CHROME,
22		FIREFOX,
23		INTERNETEXPLORER,
24		SAFARI
25
26	}
27	
28	public static WebDriver CriarWebDriver(Navegador navegador, String pathWebDriver) {
29		
30		try {
31			
32			PageLoadStrategy pageLoadStrategy = PageLoadStrategy.NORMAL;
33			
34			switch (navegador) {
35			case CHROME:
36				System.setProperty("webdriver.chrome.driver", pathWebDriver);
37				ChromeOptions chromeOptions = new ChromeOptions();
38				chromeOptions.setPageLoadStrategy(pageLoadStrategy);
39				driver = new ChromeDriver(chromeOptions);
40				break;
41			case FIREFOX:
42				System.setProperty("webdriver.gecko.driver", pathWebDriver);
43				FirefoxOptions firefoxOptions = new FirefoxOptions();
44				firefoxOptions.setPageLoadStrategy(pageLoadStrategy);
45				driver = new FirefoxDriver(firefoxOptions);
46				break;
47			case INTERNETEXPLORER:
48				System.setProperty("webdriver.ie.driver", pathWebDriver);
49				InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
50				internetExplorerOptions.setPageLoadStrategy(pageLoadStrategy);
51				driver = new InternetExplorerDriver(internetExplorerOptions);
52				break;
53			default:
54				Assert.fail("Não foi possível iniciar o WebDriver: " + navegador.toString());
55				break;
56			}
57			
58		} catch (Exception e) {
59			Assert.fail(e.toString());
60		}
61		
62		return driver;
63	}
64	
65	
66	public static WebDriver CriarWebDriver(Navegador navegador) {
67		
68		try {
69			
70			PageLoadStrategy pageLoadStrategy = PageLoadStrategy.NORMAL;
71			
72			switch (navegador) {
73			case CHROME:
74				WebDriverManager.chromedriver().setup();
75				ChromeOptions chromeOptions = new ChromeOptions();
76				chromeOptions.setPageLoadStrategy(pageLoadStrategy);
77				driver = new ChromeDriver(chromeOptions);
78				break;
79			case FIREFOX:
80				WebDriverManager.firefoxdriver().setup();
81				FirefoxOptions firefoxOptions = new FirefoxOptions();
82				firefoxOptions.setPageLoadStrategy(pageLoadStrategy);
83				driver = new FirefoxDriver(firefoxOptions);
84				break;
85			case INTERNETEXPLORER:
86				WebDriverManager.iedriver().setup();
87				InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
88				internetExplorerOptions.setPageLoadStrategy(pageLoadStrategy);
89				driver = new InternetExplorerDriver(internetExplorerOptions);
90				break;
91			default:
92				Assert.fail("Não foi possível iniciar o WebDriver: " + navegador.toString());
93				break;
94			}
95			
96		} catch (Exception e) {
97			Assert.fail(e.toString());
98		}
99		
100		return driver;
101	}
102
103}
104
Full Screen
copy
1package driver;
2
3
4import io.github.bonigarcia.wdm.WebDriverManager;
5import io.github.bonigarcia.wdm.config.DriverManagerType;
6import org.openqa.selenium.PageLoadStrategy;
7import org.openqa.selenium.WebDriver;
8import org.openqa.selenium.chrome.ChromeDriver;
9import org.openqa.selenium.chrome.ChromeOptions;
10import org.openqa.selenium.firefox.FirefoxDriver;
11import org.openqa.selenium.firefox.FirefoxOptions;
12import org.openqa.selenium.remote.AbstractDriverOptions;
13
14public enum BrowsersFactory {
15    CHROME{
16
17        public ChromeOptions getOptions() {
18            ChromeOptions chromeOptions = new ChromeOptions();
19            chromeOptions.addArguments("−−incognito");
20            chromeOptions.addArguments("--disable-infobars");
21            chromeOptions.addArguments("--disable-notifications");
22            //chromeOptions.setHeadless(configuration().headless());
23            chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
24            return chromeOptions;
25        }
26        @Override
27        public WebDriver createDriver() {
28            WebDriverManager.getInstance(DriverManagerType.CHROME).setup();
29            return new ChromeDriver(getOptions());
30
31        }
32
33    }, FIREFOX{
34
35
36        public FirefoxOptions getOptions() {
37            FirefoxOptions firefoxOptions = new FirefoxOptions();
38            firefoxOptions.addArguments();
39            firefoxOptions.addArguments("--disable-infobars");
40            firefoxOptions.addArguments("--disable-notifications");
41            firefoxOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
42            //firefoxOptions.setHeadless(configuration().headless());
43            return firefoxOptions;
44        }
45        @Override
46        public WebDriver createDriver() {
47            getOptions();
48            WebDriverManager.getInstance(DriverManagerType.FIREFOX).setup();
49            return new FirefoxDriver(getOptions());
50
51        }
52    };
53
54
55    public abstract WebDriver createDriver();
56
57
58}
59
60
61
Full Screen
copy
1package com.ostapiuk.core.driver;
2
3import io.github.bonigarcia.wdm.ChromeDriverManager;
4import io.github.bonigarcia.wdm.DriverManagerType;
5import io.github.bonigarcia.wdm.FirefoxDriverManager;
6import org.openqa.selenium.PageLoadStrategy;
7import org.openqa.selenium.WebDriver;
8import org.openqa.selenium.chrome.ChromeDriver;
9import org.openqa.selenium.chrome.ChromeOptions;
10import org.openqa.selenium.firefox.FirefoxDriver;
11
12public enum DriverProviderFactory {
13    CHROME {
14        @Override
15        public WebDriver create() {
16            ChromeDriverManager.getInstance(DriverManagerType.CHROME).setup();
17            ChromeOptions options = new ChromeOptions();
18            options.setPageLoadStrategy(PageLoadStrategy.EAGER);
19            return new ChromeDriver(options);
20        }
21    }, FIREFOX {
22        @Override
23        public WebDriver create() {
24            FirefoxDriverManager.getInstance(DriverManagerType.FIREFOX).setup();
25            return new FirefoxDriver();
26        }
27    };
28
29    public abstract WebDriver create();
30}
31
32
33
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on Enum-PageLoadStrategy

    No relevant questions found for this class 😞

Most used methods in Enum-PageLoadStrategy

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)