In Selenium 3, capabilities were defined in a session by using Desired Capabilities classes.
As of Selenium 4, you must use the browser options classes.
For remote driver sessions, a browser options instance is required as it determines which browser will be used.
These options are described in the w3c specification for Capabilities.
Each browser has custom options that may be defined in addition to the ones defined in the specification.
browserName
Browser name is set by default when using an Options class instance.
packagedev.selenium.drivers;importdev.selenium.BaseTest;importjava.time.Duration;importjava.time.temporal.ChronoUnit;importorg.junit.jupiter.api.Test;importorg.junit.jupiter.api.Assertions;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.UnexpectedAlertBehaviour;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.remote.CapabilityType;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=newChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=newChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=newChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=newChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setScriptTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getScriptTimeout();Assertions.assertEquals(timeout,duration,"The script timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetPageLoadTimeout(){ChromeOptionschromeOptions=newChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setPageLoadTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getPageLoadTimeout();Assertions.assertEquals(timeout,duration,"The page load timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetImplicitWaitTimeout(){ChromeOptionschromeOptions=newChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setImplicitWaitTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getImplicitWaitTimeout();Assertions.assertEquals(timeout,duration,"The implicit wait timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetUnhandledPromptBehaviour(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR);Assertions.assertNotNull(capabilityObject,"Capability UNHANDLED_PROMPT_BEHAVIOUR should not be null.");Assertions.assertEquals(capabilityObject.toString(),UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY.toString());}@TestpublicvoidsetWindowRect(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT,true);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);Assertions.assertNotNull(capabilityObject,"Capability SET_WINDOW_RECT should not be null.");Booleancapability=(Boolean)capabilityObject;Assertions.assertTrue(capability,"The capability SET_WINDOW_RECT should be set to true.");}@TestpublicvoidsetStrictFileInteractability(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY,true);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);Assertions.assertNotNull(capabilityObject,"Capability STRICT_FILE_INTERACTABILITY should not be null.");Booleancapability=(Boolean)capabilityObject;Assertions.assertTrue(capability,"The capability STRICT_FILE_INTERACTABILITY should be set to true.");}}
options.set_window_rect=True# Full support in Firefoxdriver=webdriver.Firefox(options=options)
fromseleniumimportwebdriverfromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=webdriver.ChromeOptions()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=webdriver.ChromeOptions()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=webdriver.ChromeOptions()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_capabilities():options=webdriver.ChromeOptions()options.browser_version='stable'options.platform_name='any'options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=webdriver.ChromeOptions()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=webdriver.ChromeOptions()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=webdriver.ChromeOptions()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=webdriver.ChromeOptions()options.unhandled_prompt_behavior='accept'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_set_window_rect():options=webdriver.FirefoxOptions()options.set_window_rect=True# Full support in Firefoxdriver=webdriver.Firefox(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_strict_file_interactability():options=webdriver.ChromeOptions()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=webdriver.ChromeOptions()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()
This capability is optional, this is used to set the available browser version at remote end.
In recent versions of Selenium, if the version is not found on the system,
it will be automatically downloaded by Selenium Manager
packagedev.selenium.drivers;importdev.selenium.BaseTest;importjava.time.Duration;importjava.time.temporal.ChronoUnit;importorg.junit.jupiter.api.Test;importorg.junit.jupiter.api.Assertions;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.UnexpectedAlertBehaviour;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.remote.CapabilityType;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=newChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=newChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=newChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=newChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setScriptTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getScriptTimeout();Assertions.assertEquals(timeout,duration,"The script timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetPageLoadTimeout(){ChromeOptionschromeOptions=newChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setPageLoadTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getPageLoadTimeout();Assertions.assertEquals(timeout,duration,"The page load timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetImplicitWaitTimeout(){ChromeOptionschromeOptions=newChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setImplicitWaitTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getImplicitWaitTimeout();Assertions.assertEquals(timeout,duration,"The implicit wait timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetUnhandledPromptBehaviour(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR);Assertions.assertNotNull(capabilityObject,"Capability UNHANDLED_PROMPT_BEHAVIOUR should not be null.");Assertions.assertEquals(capabilityObject.toString(),UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY.toString());}@TestpublicvoidsetWindowRect(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT,true);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);Assertions.assertNotNull(capabilityObject,"Capability SET_WINDOW_RECT should not be null.");Booleancapability=(Boolean)capabilityObject;Assertions.assertTrue(capability,"The capability SET_WINDOW_RECT should be set to true.");}@TestpublicvoidsetStrictFileInteractability(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY,true);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);Assertions.assertNotNull(capabilityObject,"Capability STRICT_FILE_INTERACTABILITY should not be null.");Booleancapability=(Boolean)capabilityObject;Assertions.assertTrue(capability,"The capability STRICT_FILE_INTERACTABILITY should be set to true.");}}
fromseleniumimportwebdriverfromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=webdriver.ChromeOptions()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=webdriver.ChromeOptions()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=webdriver.ChromeOptions()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_capabilities():options=webdriver.ChromeOptions()options.browser_version='stable'options.platform_name='any'options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=webdriver.ChromeOptions()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=webdriver.ChromeOptions()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=webdriver.ChromeOptions()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=webdriver.ChromeOptions()options.unhandled_prompt_behavior='accept'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_set_window_rect():options=webdriver.FirefoxOptions()options.set_window_rect=True# Full support in Firefoxdriver=webdriver.Firefox(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_strict_file_interactability():options=webdriver.ChromeOptions()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=webdriver.ChromeOptions()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()
Three types of page load strategies are available.
The page load strategy queries the
document.readyState
as described in the table below:
Strategy
Ready State
Notes
normal
complete
Used by default, waits for all resources to download
eager
interactive
DOM access is ready, but other resources like images may still be loading
none
Any
Does not block WebDriver at all
The document.readyState property of a document describes the loading state of the current document.
When navigating to a new page via URL, by default, WebDriver will hold off on completing a navigation
method (e.g., driver.navigate().get()) until the document ready state is complete. This does not
necessarily mean that the page has finished loading, especially for sites like Single Page Applications
that use JavaScript to dynamically load content after the Ready State returns complete. Note also
that this behavior does not apply to navigation that is a result of clicking an element or submitting a form.
If a page takes a long time to load as a result of downloading assets (e.g., images, css, js)
that aren’t important to the automation, you can change from the default parameter of normal to
eager or none to speed up the session. This value applies to the entire session, so make sure
that your waiting strategy is sufficient to minimize
flakiness.
normal (default)
WebDriver waits until the load
event fire is returned.
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
it('Navigate using normal page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.google.com');
constChrome=require('selenium-webdriver/chrome');const{suite}=require('selenium-webdriver/testing');const{Browser}=require("selenium-webdriver");constoptions=newChrome.Options()suite(function(env){describe('Page loading strategies',function(){it('Navigate using eager page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('eager')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});it('Navigate using none page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('none')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});it('Navigate using normal page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});});},{browsers:[Browser.CHROME,Browser.FIREFOX]});
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
constChrome=require('selenium-webdriver/chrome');const{suite}=require('selenium-webdriver/testing');const{Browser}=require("selenium-webdriver");constoptions=newChrome.Options()suite(function(env){describe('Page loading strategies',function(){it('Navigate using eager page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('eager')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});it('Navigate using none page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('none')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});it('Navigate using normal page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});});},{browsers:[Browser.CHROME,Browser.FIREFOX]});
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
constChrome=require('selenium-webdriver/chrome');const{suite}=require('selenium-webdriver/testing');const{Browser}=require("selenium-webdriver");constoptions=newChrome.Options()suite(function(env){describe('Page loading strategies',function(){it('Navigate using eager page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('eager')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});it('Navigate using none page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('none')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});it('Navigate using normal page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});});},{browsers:[Browser.CHROME,Browser.FIREFOX]});
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
This capability checks whether an expired (or)
invalid TLS Certificate is used while navigating
during a session.
If the capability is set to false, an
insecure certificate error
will be returned as navigation encounters any domain
certificate problems. If set to true, invalid certificate will be
trusted by the browser.
All self-signed certificates will be trusted by this capability by default.
Once set, acceptInsecureCerts capability will have an
effect for the entire session.
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
constChrome=require('selenium-webdriver/chrome');const{suite}=require('selenium-webdriver/testing');const{Browser}=require("selenium-webdriver");constoptions=newChrome.Options()suite(function(env){describe('Page loading strategies',function(){it('Navigate using eager page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('eager')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});it('Navigate using none page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('none')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});it('Navigate using normal page loading strategy',asyncfunction(){letdriver=awaitenv.builder().setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});});},{browsers:[Browser.CHROME,Browser.FIREFOX]});
A WebDriver session is imposed with a certain session timeout
interval, during which the user can control the behaviour
of executing scripts or retrieving information from the browser.
Each session timeout is configured with
combination of different timeouts as described below:
Script Timeout
Specifies when to interrupt an executing script in
a current browsing context. The default timeout 30,000
is imposed when a new session is created by WebDriver.
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
Specifies the time interval in which web page
needs to be loaded in a current browsing context.
The default timeout 300,000 is imposed when a
new session is created by WebDriver. If page load limits
a given/default time frame, the script will be stopped by
TimeoutException.
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
This specifies the time to wait for the
implicit element location strategy when
locating elements. The default timeout 0
is imposed when a new session is created by WebDriver.
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
Specifies the state of current session’s user prompt handler.
Defaults to dismiss and notify state
User Prompt Handler
This defines what action must take when a
user prompt encounters at the remote-end. This is defined by
unhandledPromptBehavior capability and has the following states:
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
This new capability indicates if strict interactability checks
should be applied to input type=file elements. As strict interactability
checks are off by default, there is a change in behaviour
when using Element Send Keys with hidden file upload controls.
packagedev.selenium.drivers;importdev.selenium.BaseTest;importorg.junit.jupiter.api.Test;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.chrome.ChromeDriver;publicclassOptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=newChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}}
A proxy server acts as an intermediary for
requests between a client and a server. In simple terms,
the traffic flows through the proxy server
on its way to the address you requested and back.
A proxy server for automation scripts
with Selenium could be helpful for:
Capture network traffic
Mock backend calls made by the website
Access the required website under complex network
topologies or strict corporate restrictions/policies.
If you are in a corporate environment, and a
browser fails to connect to a URL, this is most
likely because the environment needs a proxy to be accessed.
Selenium WebDriver provides a way to proxy settings: