ブラウザーオプション

これらの機能はすべてのブラウザで共有されています。

Selenium 3 では、Capabilitiesは Desired Capabilities クラスを使用してセッションで定義していました。 Selenium 4 以降、ブラウザ オプション クラスを使用する必要があります。 リモート ドライバー セッションの場合、使用するブラウザーを決めるため、ブラウザーオプションインスタンスが必要です。

これらのオプションは、Capabilities の w3c仕様で説明しています。

各ブラウザには、w3c仕様で定義しているものに加えて定義可能な カスタム オプション があります。

browserName

オプションクラスのインスタンスを使用すると、ブラウザ名はデフォルトで設定されます。

	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.chrome
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

browserVersion

この機能はオプションであり、リモート側で使用可能なブラウザのバージョンを設定するために使用されます。最近のSeleniumのバージョンでは、システムにバージョンが見つからない場合、Selenium Manager によって自動的にダウンロードされます。

	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options.browser_version = 'latest'
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

pageLoadStrategy

3種類のページ読み込み戦略を利用できます。

ページ読み込み戦略は、次の表で説明しています。

戦略準備完了状態注釈
normalcompleteデフォルトで使用され、すべてのリソースをダウンロードするのを待ちます
eagerinteractiveDOM アクセスの準備は整っていますが、画像などの他のリソースはまだロード中の可能性があります
noneAnyWebDriver をまったくブロックしません

ドキュメントの document.readyState プロパティは、現在のドキュメントの読み込み状態を示します。

URL 経由で新しいページに移動する場合、デフォルトでは、WebDriver は、ドキュメントの準備完了状態が完了するまで、 ナビゲーション メソッド (driver.navigate().get() など) の完了を保留します。 これは必ずしもページの読み込みが完了したことを意味するわけではありません。 特に、Ready State が完了した後に JavaScript を使用してコンテンツを動的に読み込むシングル ページ アプリケーションのようなサイトの場合はそうです。 また、この動作は、要素のクリックまたはフォームの送信の結果であるナビゲーションには適用されないことに注意してください。

自動化にとって重要ではないアセット (画像、css、js など) をダウンロードした結果、ページの読み込みに時間がかかる場合は、 デフォルトのパラメーターである normaleager または none に変更して、セッションの読み込みを高速化できます。 この値はセッション全体に適用されるため、 待機戦略 が不安定さを最小限に抑えるのに十分であることを確認してください。

normal (デフォルト)

WebDriver は load イベント検知するまで待機します。

    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.page_load_strategy = 'normal'
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace pageLoadStrategy {
  class pageLoadStrategy {
    public static void Main(string[] args) {
      var chromeOptions = new ChromeOptions();
      chromeOptions.PageLoadStrategy = PageLoadStrategy.Normal;
      IWebDriver driver = new ChromeDriver(chromeOptions);
      try {
        driver.Navigate().GoToUrl("https://example.com");
      } finally {
        driver.Quit();
      }
    }
  }
}
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('normal'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
Show full example
const Chrome = require('selenium-webdriver/chrome');
const {Browser, Builder} = require("selenium-webdriver");
const options = new Chrome.Options()


describe('Page loading strategies', function () {
  it('Navigate using eager page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('eager'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Navigate using none page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('none'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Navigate using normal page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('normal'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Should be able to accept certs', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setAcceptInsecureCerts(true))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });
});
import org.openqa.selenium.PageLoadStrategy
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

fun main() {
  val chromeOptions = ChromeOptions()
  chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL)
  val driver = ChromeDriver(chromeOptions)
  try {
    driver.get("https://www.google.com")
  }
  finally {
    driver.quit()
  }
}

eager

WebDriver は、DOMContentLoaded イベントを検知するまで待機します。

    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.page_load_strategy = 'eager'
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace pageLoadStrategy {
  class pageLoadStrategy {
    public static void Main(string[] args) {
      var chromeOptions = new ChromeOptions();
      chromeOptions.PageLoadStrategy = PageLoadStrategy.Eager;
      IWebDriver driver = new ChromeDriver(chromeOptions);
      try {
        driver.Navigate().GoToUrl("https://example.com");
      } finally {
        driver.Quit();
      }
    }
  }
}
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('eager'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
Show full example
const Chrome = require('selenium-webdriver/chrome');
const {Browser, Builder} = require("selenium-webdriver");
const options = new Chrome.Options()


describe('Page loading strategies', function () {
  it('Navigate using eager page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('eager'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Navigate using none page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('none'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Navigate using normal page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('normal'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Should be able to accept certs', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setAcceptInsecureCerts(true))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });
});
import org.openqa.selenium.PageLoadStrategy
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

fun main() {
  val chromeOptions = ChromeOptions()
  chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER)
  val driver = ChromeDriver(chromeOptions)
  try {
    driver.get("https://www.google.com")
  }
  finally {
    driver.quit()
  }
}

none

WebDriver は、最初のページがダウンロードされるまで待機します。

    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.page_load_strategy = 'none'
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace pageLoadStrategy {
  class pageLoadStrategy {
    public static void Main(string[] args) {
      var chromeOptions = new ChromeOptions();
      chromeOptions.PageLoadStrategy = PageLoadStrategy.None;
      IWebDriver driver = new ChromeDriver(chromeOptions);
      try {
        driver.Navigate().GoToUrl("https://example.com");
      } finally {
        driver.Quit();
      }
    }
  }
}
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('none'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
Show full example
const Chrome = require('selenium-webdriver/chrome');
const {Browser, Builder} = require("selenium-webdriver");
const options = new Chrome.Options()


describe('Page loading strategies', function () {
  it('Navigate using eager page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('eager'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Navigate using none page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('none'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Navigate using normal page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('normal'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Should be able to accept certs', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setAcceptInsecureCerts(true))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });
});
import org.openqa.selenium.PageLoadStrategy
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

fun main() {
  val chromeOptions = ChromeOptions()
  chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE)
  val driver = ChromeDriver(chromeOptions)
  try {
    driver.get("https://www.google.com")
  }
  finally {
    driver.quit()
  }
}

platformName

これにより、リモートエンドのオペレーティングシステムが識別され、 platformName を取得するとOS名が返されます。

クラウドベースのプロバイダーでは、 platformName を設定すると、リモートエンドのOSが設定されます。

	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

acceptInsecureCerts

この機能は、セッション中のナビゲーション中に、期限切れ(または)無効な TLS証明書 が使用されているかどうかを確認します。

機能が false に設定されている場合、ナビゲーションでドメイン証明書の問題が発生すると、 insecure certificate error が返されます。 true に設定すると、無効な証明書はブラウザーによって信頼されます。

すべての自己署名証明書は、デフォルトでこの機能によって信頼されます。 一度設定すると、 acceptInsecureCerts Capabilityはセッション全体に影響します。

    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setAcceptInsecureCerts(true))
      .build();
Show full example
const Chrome = require('selenium-webdriver/chrome');
const {Browser, Builder} = require("selenium-webdriver");
const options = new Chrome.Options()


describe('Page loading strategies', function () {
  it('Navigate using eager page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('eager'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Navigate using none page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('none'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Navigate using normal page loading strategy', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setPageLoadStrategy('normal'))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });

  it('Should be able to accept certs', async function () {
    let driver = new Builder()
      .forBrowser(Browser.CHROME)
      .setChromeOptions(options.setAcceptInsecureCerts(true))
      .build();

    await driver.get('https://www.selenium.dev/selenium/web/blank.html');
    await driver.quit();
  });
});

timeouts

WebDriverの セッション には特定の セッションタイムアウト 間隔が設定されており、 その間、ユーザーはスクリプトの実行またはブラウザーからの情報の取得の動作を制御できます。

各セッションタイムアウトは、以下で説明するように、異なる タイムアウト の組み合わせで構成されます。

Script Timeout:

現在のブラウジングコンテキストで実行中のスクリプトをいつ中断するかを指定します。 新しいセッションがWebDriverによって作成されると、デフォルトのタイムアウト 30,000 が課されます。

	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

Page Load Timeout:

現在のブラウジングコンテキストでWebページをロードする必要がある時間間隔を指定します。 新しいセッションがWebDriverによって作成されると、デフォルトのタイムアウト 300,000 が課されます。 ページの読み込みが指定/デフォルトの時間枠を制限する場合、スクリプトは TimeoutException によって停止されます。

	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.timeouts = { 'pageLoad': 5000 }
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

Implicit Wait Timeout

これは、要素を検索するときに暗黙的な要素の検索戦略を待つ時間を指定します。 新しいセッションがWebDriverによって作成されると、デフォルトのタイムアウト 0 が課されます。

	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.timeouts = { 'implicit': 5000 }
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

unhandledPromptBehavior

現在のセッションの ユーザープロンプトハンドラー の状態を指定します。 デフォルトでは、 dismiss and notify (却下して通知する) 状態 となります。

User Prompt Handler

これは、リモートエンドでユーザープロンプトが表示されたときに実行する必要があるアクションを定義します。 これは、 unhandledPromptBehavior Capabilityによって定義され、次の状態があります。

  • dismiss (却下)
  • accept (受入)
  • dismiss and notify (却下して通知)
  • accept and notify (受け入れて通知)
  • ignore (無視)
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.unhandled_prompt_behavior = 'accept'
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

setWindowRect

リモート エンドがすべての サイズ変更および再配置 コマンド をサポートするかどうかを示します。

   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

strictFileInteractability

この新しいcapabilityは、厳密な相互作用チェックを input type = file 要素に適用する必要があるかどうかを示します。 厳密な相互作用チェックはデフォルトでオフになっているため、隠しファイルのアップロードコントロールで Element Send Keys を使用する場合の動作が変更されます。

    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
Show full example
package dev.selenium.drivers;

import dev.selenium.BaseTest;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.chrome.ChromeDriver;

public class OptionsTest extends BaseTest {

  @Test
  public void setPageLoadStrategyNormal() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyEager() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setPageLoadStrategyNone() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void setAcceptInsecureCerts() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setAcceptInsecureCerts(true);
    WebDriver driver = new ChromeDriver(chromeOptions);
    try {
      // Navigate to Url
      driver.get("https://selenium.dev");
    } finally {
      driver.quit();
    }
  }

  @Test
  public void getBrowserName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String name = chromeOptions.getBrowserName();
	Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty");
  }

  @Test
  public void setBrowserVersion() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String version = "latest";
	chromeOptions.setBrowserVersion(version);
	Assertions.assertEquals(version, chromeOptions.getBrowserVersion());
  }

  @Test
  public void setPlatformName() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	String platform = "OS X 10.6";
	chromeOptions.setPlatformName(platform);
	Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString());
  }

  @Test
  public void setScriptTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setScriptTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getScriptTimeout();
	  Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setPageLoadTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setPageLoadTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
	  Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setImplicitWaitTimeout() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	Duration duration = Duration.of(5, ChronoUnit.SECONDS);
	chromeOptions.setImplicitWaitTimeout(duration);

	WebDriver driver = new ChromeDriver(chromeOptions);
	try {
	  Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout();
	  Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds.");
	} finally {
	  driver.quit();
	}
  }

  @Test
  public void setUnhandledPromptBehaviour() {
	ChromeOptions chromeOptions = getDefaultChromeOptions();
	chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);
	//verify the capability object is not null
	Object capabilityObject = 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());
  }

  @Test
  public void setWindowRect() {
   	ChromeOptions chromeOptions = getDefaultChromeOptions();
   	chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true);
   	//verify the capability object is not null
   	Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);
    Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true.");
  }
	
  @Test
  public void setStrictFileInteractability() {
    ChromeOptions chromeOptions = getDefaultChromeOptions();
    chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true);
	//verify the capability object is not null
    Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);
    Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null.");

    Boolean capability = (Boolean) capabilityObject;
    Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true.");
  }
}

    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end

proxy

プロキシサーバーは、クライアントとサーバー間の要求の仲介役として機能します。 簡単に言えば、トラフィックはプロキシサーバーを経由して、要求したアドレスに戻り、戻ってきます。

Seleniumを使用した自動化スクリプト用のプロキシサーバーは、

  • ネットワークトラフィックをキャプチャする
  • ウェブサイトによって行われた模擬バックエンドを呼び出す
  • 複雑なネットワークトポロジーまたは厳格な企業の制限/ポリシーの下で、必要なWebサイトにアクセスします。

企業環境でブラウザがURLへの接続に失敗した場合、環境にアクセスするにはプロキシが必要であることが原因であることが最も可能性が高いです。

Selenium WebDriverは設定をプロキシする方法を提供します。

Move Code

import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class ProxyTest {
  public static void main(String[] args) {
    Proxy proxy = new Proxy();
    proxy.setHttpProxy("<HOST:PORT>");
    ChromeOptions options = new ChromeOptions();
    options.setCapability("proxy", proxy);
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://www.google.com/");
    driver.manage().window().maximize();
    driver.quit();
  }
}
    options = get_default_chrome_options()
    options.proxy = Proxy({ 'proxyType': ProxyType.MANUAL, 'httpProxy' : 'http.proxy:1234'})
    driver = webdriver.Chrome(options=options)
Show full example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType


def test_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()


def test_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()


def test_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()

def test_timeouts_script():
    options = get_default_chrome_options()
    options.timeouts = { 'script': 5000 }
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()

def test_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()

def test_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()

def test_set_window_rect():
    options = webdriver.FirefoxOptions()
    options.set_window_rect = True # Full support in Firefox
    driver = webdriver.Firefox(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_strict_file_interactability():
    options = get_default_chrome_options()
    options.strict_file_interactability = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def test_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()
    
def test_set_browser_name():
    options = get_default_chrome_options()
    assert options.capabilities['browserName'] == 'chrome'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_set_browser_version():
    options = get_default_chrome_options()
    options.browser_version = 'stable'
    assert options.capabilities['browserVersion'] == 'stable'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_platform_name():
    options = get_default_chrome_options()
    options.platform_name = 'any'
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()
    
def test_accept_insecure_certs():
    options = get_default_chrome_options()
    options.accept_insecure_certs = True
    driver = webdriver.Chrome(options=options)
    driver.get("https://www.selenium.dev/")
    driver.quit()

def get_default_chrome_options():
    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    return options
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

public class ProxyTest{
public static void Main() {
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.SslProxy = "<HOST:PORT>";
options.Proxy = proxy;
options.AddArgument("ignore-certificate-errors");
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://www.selenium.dev/");
}
}
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')
Show full example
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Chrome' do
  describe 'Driver Options' do
    let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
    let(:url) { 'https://www.selenium.dev/selenium/web/' }

    it 'page load strategy normal' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :normal

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy eager' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :eager

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'page load strategy none' do
      options = Selenium::WebDriver::Options.chrome
      options.page_load_strategy = :none

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets remote capabilities', skip: 'this is example code that will not execute' do
      options = Selenium::WebDriver::Options.firefox
      options.platform_name = 'Windows 10'
      options.browser_version = 'latest'
      cloud_options = {}
      cloud_options[:build] = my_test_build
      cloud_options[:name] = my_test_name
      options.add_option('cloud:options', cloud_options)
      driver = Selenium::WebDriver.for :remote, capabilities: options
      driver.get(url)
      driver.quit
    end

    it 'accepts untrusted certificates' do
      options = Selenium::WebDriver::Options.chrome
      options.accept_insecure_certs = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets unhandled prompt behavior' do
      options = Selenium::WebDriver::Options.chrome
      options.unhandled_prompt_behavior = :accept

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets window rect' do
      options = Selenium::WebDriver::Options.firefox
      options.set_window_rect = true

      driver = Selenium::WebDriver.for :firefox, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets strict file interactability' do
      options = Selenium::WebDriver::Options.chrome
      options.strict_file_interactability = true

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the proxy' do
      options = Selenium::WebDriver::Options.chrome
      options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the implicit timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {implicit: 1}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the page load timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {page_load: 400_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets the script timeout' do
      options = Selenium::WebDriver::Options.chrome
      options.timeouts = {script: 40_000}

      driver = Selenium::WebDriver.for :chrome, options: options
      driver.get(url)
      driver.quit
    end

    it 'sets capabilities in the pre-selenium 4 way', skip: 'this is example code that will not execute' do
      caps = Selenium::WebDriver::Remote::Capabilities.firefox
      caps[:platform] = 'Windows 10'
      caps[:version] = '92'
      caps[:build] = my_test_build
      caps[:name] = my_test_name
      driver = Selenium::WebDriver.for :remote, url: cloud_url, desired_capabilities: caps
      driver.get(url)
      driver.quit
    end
  end
end
let webdriver = require('selenium-webdriver');
let chrome = require('selenium-webdriver/chrome');
let proxy = require('selenium-webdriver/proxy');
let opts = new chrome.Options();

(async function example() {
opts.setProxy(proxy.manual({http: '<HOST:PORT>'}));
let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(opts)
.build();
try {
await driver.get("https://selenium.dev");
}
finally {
await driver.quit();
}
}());
import org.openqa.selenium.Proxy
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

class proxyTest {
fun main() {

        val proxy = Proxy()
        proxy.setHttpProxy("<HOST:PORT>")
        val options = ChromeOptions()
        options.setCapability("proxy", proxy)
        val driver: WebDriver = ChromeDriver(options)
        driver["https://www.google.com/"]
        driver.manage().window().maximize()
        driver.quit()
    }
}