Tune in for the Selenium Community Live scheduled for April 25th, 2025.
Join us!
Opções do navegador
Esses recursos são compartilhados por todos os navegadores.
Page being translated from English to Portuguese.
Do you speak Portuguese? Help us to translate
it by sending us pull requests!
No Selenium 3, os recursos foram definidos em uma sessão usando classes de recursos desejados.
A partir do Selenium 4, você deve usar as classes de opções do navegador.
Para sessões remotas de driver, uma instância de opções do navegador é necessária, pois determina qual navegador será usado.
Essas opções são descritas na especificação w3c para Capabilities.
Cada navegador tem custom options que podem ser definidas além das definidas na especificação.
browserName
Esta capacidade é usada para definir o browserName para uma determinada sessão.
Se o navegador especificado não estiver instalado no
extremidade remota, a criação da sessão falhará.
7275
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full/examples/python/tests/drivers/test_options.py#L79-80" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
Esta capacidade é opcional, é usada para
defina a versão do navegador disponível na extremidade remota.
Por exemplo, se solicitar o Chrome versão 75 em um sistema que
tiver apenas 80 instalados, a criação da sessão falhará.
7983
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full/examples/python/tests/drivers/test_options.py#L86-88" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
Três tipos de estratégias de carregamento de página estão disponíveis.
A estratégia de carregamento da página consulta o
document.readyState
conforme descrito na tabela abaixo:
Estratégia
Estado pronto
Notas
normal
completo
Usado por padrão, aguarda o download de todos os recursos
ansioso
interativo
O acesso DOM está pronto, mas outros recursos como imagens ainda podem estar carregando
nenhum
Qualquer
Não bloqueia o WebDriver
A propriedade document.readyState de um documento descreve o estado de carregamento do documento atual.
Ao navegar para uma nova página via URL, por padrão, o WebDriver irá adiar a conclusão de uma navegação
(por exemplo, driver.navigate().get()) até que o estado pronto do documento seja concluído. isso não
significa necessariamente que a página terminou de carregar, especialmente para sites como Single Page Applications
que usam JavaScript para carregar conteúdo dinamicamente depois que o estado Pronto retorna completo. Observe também
que esse comportamento não se aplica à navegação resultante de clicar em um elemento ou enviar um formulário.
Se uma página demorar muito para carregar como resultado do download de ativos (por exemplo, imagens, css, js)
que não são importantes para a automação, você pode mudar do parâmetro padrão de normal para
eager ou none para acelerar a sessão. Esse valor se aplica a toda a sessão, portanto, certifique-se
que sua waiting strategy é suficiente para minimizar
descamação.
normal (default)
WebDriver waits until the load
event fire is returned.
2024
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("--no-sandbox")returnoptions
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
constChrome=require('selenium-webdriver/chrome');const{Browser,Builder}=require("selenium-webdriver");constoptions=newChrome.Options()describe('Page loading strategies',function(){it('Navigate using eager page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('eager')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Navigate using none page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('none')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Navigate using normal page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Should be able to accept certs',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setAcceptInsecureCerts(true)).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});});
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("--no-sandbox")returnoptions
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
constChrome=require('selenium-webdriver/chrome');const{Browser,Builder}=require("selenium-webdriver");constoptions=newChrome.Options()describe('Page loading strategies',function(){it('Navigate using eager page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('eager')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Navigate using none page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('none')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Navigate using normal page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Should be able to accept certs',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setAcceptInsecureCerts(true)).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});});
WebDriver only waits until the initial page is downloaded.
4650
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("--no-sandbox")returnoptions
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
constChrome=require('selenium-webdriver/chrome');const{Browser,Builder}=require("selenium-webdriver");constoptions=newChrome.Options()describe('Page loading strategies',function(){it('Navigate using eager page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('eager')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Navigate using none page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('none')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Navigate using normal page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Should be able to accept certs',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setAcceptInsecureCerts(true)).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});});
This identifies the operating system at the remote-end,
fetching the platformName returns the OS name.
In cloud-based providers,
setting platformName sets the OS at the remote-end.
8791
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L94-96" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
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.
5962
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L101-103" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
constChrome=require('selenium-webdriver/chrome');const{Browser,Builder}=require("selenium-webdriver");constoptions=newChrome.Options()describe('Page loading strategies',function(){it('Navigate using eager page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('eager')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Navigate using none page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('none')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Navigate using normal page loading strategy',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setPageLoadStrategy('normal')).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});it('Should be able to accept certs',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.CHROME).setChromeOptions(options.setAcceptInsecureCerts(true)).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});});
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.
9599
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L30-32" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
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.
110114
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L37-39" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
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.
125129
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L44-46" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
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:
dismiss
accept
dismiss and notify
accept and notify
ignore
140143
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L51-53" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L58-60" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
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.
162165
Show full example
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=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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=getDefaultChromeOptions();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.");}}
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L65-67" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend
A proxy server acts as an intermediary for
requests between a client and a server. In simple,
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:
fromselenium.webdriver.common.proxyimportProxyfromselenium.webdriver.common.proxyimportProxyTypedeftest_page_load_strategy_normal():options=get_default_chrome_options()options.page_load_strategy='normal'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_eager():options=get_default_chrome_options()options.page_load_strategy='eager'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_page_load_strategy_none():options=get_default_chrome_options()options.page_load_strategy='none'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_script():options=get_default_chrome_options()options.timeouts={'script':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_page_load():options=get_default_chrome_options()options.timeouts={'pageLoad':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_timeouts_implicit_wait():options=get_default_chrome_options()options.timeouts={'implicit':5000}driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_unhandled_prompt():options=get_default_chrome_options()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=get_default_chrome_options()options.strict_file_interactability=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()deftest_proxy():options=get_default_chrome_options()options.proxy=Proxy({'proxyType':ProxyType.MANUAL,'httpProxy':'http.proxy:1234'})driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_name():options=get_default_chrome_options()assertoptions.capabilities['browserName']=='chrome'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_set_browser_version():options=get_default_chrome_options()options.browser_version='stable'assertoptions.capabilities['browserVersion']=='stable'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_platform_name():options=get_default_chrome_options()options.platform_name='any'driver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit() deftest_accept_insecure_certs():options=get_default_chrome_options()options.accept_insecure_certs=Truedriver=webdriver.Chrome(options=options)driver.get("https://www.selenium.dev/")driver.quit()defget_default_chrome_options():options=webdriver.ChromeOptions()options.add_argument("–no-sandbox")returnoptions
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full//examples/python/tests/drivers/test_options.py#L72-74" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Chrome'dodescribe'Driver Options'dolet(:chrome_location){driver_finder&&ENV.fetch('CHROME_BIN',nil)}let(:url){'https://www.selenium.dev/selenium/web/'}it'page load strategy normal'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:normaldriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy eager'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:eagerdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'page load strategy none'dooptions=Selenium::WebDriver::Options.chromeoptions.page_load_strategy=:nonedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets remote capabilities',skip:'this is example code that will not execute'dooptions=Selenium::WebDriver::Options.firefoxoptions.platform_name='Windows 10'options.browser_version='latest'cloud_options={}cloud_options[:build]=my_test_buildcloud_options[:name]=my_test_nameoptions.add_option('cloud:options',cloud_options)driver=Selenium::WebDriver.for:remote,capabilities:optionsdriver.get(url)driver.quitendit'accepts untrusted certificates'dooptions=Selenium::WebDriver::Options.chromeoptions.accept_insecure_certs=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets unhandled prompt behavior'dooptions=Selenium::WebDriver::Options.chromeoptions.unhandled_prompt_behavior=:acceptdriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets window rect'dooptions=Selenium::WebDriver::Options.firefoxoptions.set_window_rect=truedriver=Selenium::WebDriver.for:firefox,options:optionsdriver.get(url)driver.quitendit'sets strict file interactability'dooptions=Selenium::WebDriver::Options.chromeoptions.strict_file_interactability=truedriver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the proxy'dooptions=Selenium::WebDriver::Options.chromeoptions.proxy=Selenium::WebDriver::Proxy.new(http:'myproxy.com:8080')driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the implicit timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={implicit:1}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the page load timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={page_load:400_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets the script timeout'dooptions=Selenium::WebDriver::Options.chromeoptions.timeouts={script:40_000}driver=Selenium::WebDriver.for:chrome,options:optionsdriver.get(url)driver.quitendit'sets capabilities in the pre-selenium 4 way',skip:'this is example code that will not execute'docaps=Selenium::WebDriver::Remote::Capabilities.firefoxcaps[:platform]='Windows 10'caps[:version]='92'caps[:build]=my_test_buildcaps[:name]=my_test_namedriver=Selenium::WebDriver.for:remote,url:cloud_url,desired_capabilities:capsdriver.get(url)driver.quitendendend