Driver Sessions

Starting and stopping a session is for opening and closing a browser.

Creating Sessions

Creating a new session corresponds with the W3C command for New session

The session is created automatically by initializing a new Driver class object.

Each language allows a session to be created with arguments from one of these classes (or equivalent):

  • Options to describe the kind of session you want; default values are used for local, but this is required for remote
  • Some form of HTTP Client configuration (the implementation varies between languages)
  • Listeners

Local Driver

The primary unique argument for starting a local driver includes information about starting the required driver service on the local machine.

  • Service object applies only to local drivers and provides information about the browser driver
WebDriverdriver=newChromeDriver(chromeOptions);
/examples/java/src/test/java/dev/selenium/drivers/OptionsTest.java
packagedev.selenium.drivers;importdev.selenium.BaseTest;importjava.time.Duration;importjava.time.temporal.ChronoUnit;importorg.junit.jupiter.api.Test;importorg.junit.jupiter.api.Assertions;importorg.openqa.selenium.PageLoadStrategy;importorg.openqa.selenium.UnexpectedAlertBehaviour;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeOptions;importorg.openqa.selenium.remote.CapabilityType;importorg.openqa.selenium.chrome.ChromeDriver;publicclass OptionsTestextendsBaseTest{@TestpublicvoidsetPageLoadStrategyNormal(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyEager(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetPageLoadStrategyNone(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidsetAcceptInsecureCerts(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setAcceptInsecureCerts(true);WebDriverdriver=newChromeDriver(chromeOptions);try{// Navigate to Urldriver.get("https://selenium.dev");}finally{driver.quit();}}@TestpublicvoidgetBrowserName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringname=chromeOptions.getBrowserName();Assertions.assertFalse(name.isEmpty(),"Browser name should not be empty");}@TestpublicvoidsetBrowserVersion(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringversion="latest";chromeOptions.setBrowserVersion(version);Assertions.assertEquals(version,chromeOptions.getBrowserVersion());}@TestpublicvoidsetPlatformName(){ChromeOptionschromeOptions=getDefaultChromeOptions();Stringplatform="OS X 10.6";chromeOptions.setPlatformName(platform);Assertions.assertEquals(platform,chromeOptions.getPlatformName().toString());}@TestpublicvoidsetScriptTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setScriptTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getScriptTimeout();Assertions.assertEquals(timeout,duration,"The script timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetPageLoadTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setPageLoadTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getPageLoadTimeout();Assertions.assertEquals(timeout,duration,"The page load timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetImplicitWaitTimeout(){ChromeOptionschromeOptions=getDefaultChromeOptions();Durationduration=Duration.of(5,ChronoUnit.SECONDS);chromeOptions.setImplicitWaitTimeout(duration);WebDriverdriver=newChromeDriver(chromeOptions);try{Durationtimeout=driver.manage().timeouts().getImplicitWaitTimeout();Assertions.assertEquals(timeout,duration,"The implicit wait timeout should be set to 5 seconds.");}finally{driver.quit();}}@TestpublicvoidsetUnhandledPromptBehaviour(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR);Assertions.assertNotNull(capabilityObject,"Capability UNHANDLED_PROMPT_BEHAVIOUR should not be null.");Assertions.assertEquals(capabilityObject.toString(),UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY.toString());}@TestpublicvoidsetWindowRect(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT,true);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT);Assertions.assertNotNull(capabilityObject,"Capability SET_WINDOW_RECT should not be null.");Booleancapability=(Boolean)capabilityObject;Assertions.assertTrue(capability,"The capability SET_WINDOW_RECT should be set to true.");}@TestpublicvoidsetStrictFileInteractability(){ChromeOptionschromeOptions=getDefaultChromeOptions();chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY,true);//verify the capability object is not nullObjectcapabilityObject=chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY);Assertions.assertNotNull(capabilityObject,"Capability STRICT_FILE_INTERACTABILITY should not be null.");Booleancapability=(Boolean)capabilityObject;Assertions.assertTrue(capability,"The capability STRICT_FILE_INTERACTABILITY should be set to true.");}}
 driver = webdriver.Chrome(options=options)
/examples/python/tests/drivers/test_options.py
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
 driver = new ChromeDriver(options);
/examples/dotnet/SeleniumDocs/BaseTest.cs
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace SeleniumDocs
{
 public class BaseTest
 {
 protected IWebDriver driver;
 protected Uri GridUrl;
 private Process _webserverProcess;
 private const string ServerJarName = "selenium-server-4.44.0.jar";
 private static readonly string BaseDirectory = AppContext.BaseDirectory;
 private const string RelativePathToGrid = "../../../../../";
 private readonly string _examplesDirectory = Path.GetFullPath(Path.Combine(BaseDirectory, RelativePathToGrid));
 [TestCleanup]
 public void Cleanup()
 {
 driver?.Quit();
 if (_webserverProcess != null)
 {
 StopServer();
 }
 }
 protected void StartDriver(string browserVersion = null)
 {
 ChromeOptions options = new ChromeOptions();
 if (browserVersion != null)
 {
 options.BrowserVersion = browserVersion;
 string userDataDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName());
 System.IO.Directory.CreateDirectory(userDataDir);
 options.AddArgument($"--user-data-dir={userDataDir}");
 options.AddArgument("--no-sandbox");
 options.AddArgument("--disable-dev-shm-usage");
 }
 driver = new ChromeDriver(options);
 }
 protected async Task StartServer()
 {
 if (_webserverProcess == null || _webserverProcess.HasExited)
 {
 _webserverProcess = new Process();
 _webserverProcess.StartInfo.FileName =
 RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "java.exe" : "java";
 string port = GetFreeTcpPort().ToString();
 GridUrl = new Uri("http://localhost:" + port + "/wd/hub");
 _webserverProcess.StartInfo.Arguments = " -jar " + ServerJarName +
 " standalone --port " + port +
 " --selenium-manager true --enable-managed-downloads true";
 _webserverProcess.StartInfo.WorkingDirectory = _examplesDirectory;
 _webserverProcess.Start();
 await EnsureGridIsRunningAsync();
 }
 }
 private void StopServer()
 {
 if (_webserverProcess != null && !_webserverProcess.HasExited)
 {
 _webserverProcess.Kill();
 _webserverProcess.Dispose();
 _webserverProcess = null;
 }
 }
 private static int GetFreeTcpPort()
 {
 TcpListener l = new TcpListener(IPAddress.Loopback, 0);
 l.Start();
 int port = ((IPEndPoint)l.LocalEndpoint).Port;
 l.Stop();
 return port;
 }
 private async Task EnsureGridIsRunningAsync()
 {
 DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(240));
 bool isRunning = false;
 HttpClient client = new HttpClient();
 while (!isRunning && DateTime.Now < timeout)
 {
 try
 {
 HttpResponseMessage response = await client.GetAsync(GridUrl + "/status");
 if (response.IsSuccessStatusCode)
 {
 isRunning = true;
 }
 else
 {
 await Task.Delay(1000);
 }
 }
 catch (HttpRequestException)
 {
 await Task.Delay(1000);
 }
 }
 if (!isRunning)
 {
 throw new TimeoutException("Could not confirm the remote selenium server is running within 30 seconds");
 }
 }
 }
}
 driver = Selenium::WebDriver.for :chrome, options: options
/examples/ruby/spec/drivers/options_spec.rb
# 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
 driver = new Builder()
 .forBrowser(Browser.CHROME)
 .setChromeOptions(options)
 .setChromeService(service)
 .build();
/examples/javascript/test/drivers/service.spec.js
const fs = require('fs');
const os = require('os');
const path = require('path');
const Chrome = require('selenium-webdriver/chrome');
const {Browser, Builder} = require("selenium-webdriver");
const {getBinaryPaths} = require("selenium-webdriver/common/driverFinder");
describe('Service Test', function () {
 let driver;
 let userDataDir;
 let service;
 let options;
 afterEach(async function () {
 if (driver) {
 await driver.quit();
 driver = null;
 }
 if (userDataDir) {
 fs.rmSync(userDataDir, { recursive: true, force: true });
 userDataDir = null;
 }
 });
 it('Default service', async function () {
 service = new Chrome.ServiceBuilder();
 driver = new Builder()
 .forBrowser(Browser.CHROME)
 .setChromeService(service)
 .build();
 await driver.get('https://www.selenium.dev/selenium/web/blank.html');
 });
 it('Set Driver Location', async function () {
 options = new Chrome.Options();
 options.setBrowserVersion("stable");
 let paths = getBinaryPaths(options);
 let driverPath = paths.driverPath;
 let browserPath = paths.browserPath;
 options.setChromeBinaryPath(browserPath);
 userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'chrome-profile-'));
 options.addArguments(`--user-data-dir=${userDataDir}`);
 options.addArguments('--no-sandbox');
 options.addArguments('--disable-dev-shm-usage');
 service = new Chrome.ServiceBuilder(driverPath);
 driver = new Builder()
 .forBrowser(Browser.CHROME)
 .setChromeOptions(options)
 .setChromeService(service)
 .build();
 await driver.get('https://www.selenium.dev/selenium/web/blank.html');
 });
 it('Set port', async function () {
 service = new Chrome.ServiceBuilder().setPort(1234);
 driver = new Builder()
 .forBrowser(Browser.CHROME)
 .setChromeService(service)
 .build();
 await driver.get('https://www.selenium.dev/selenium/web/blank.html');
 });
});

Remote Driver

The primary unique argument for starting a remote driver includes information about where to execute the code. Read the details in the Remote Driver Section

Quitting Sessions

Quitting a session corresponds to W3C command for Deleting a Session.

Important note: the quit method is different from the close method, and it is recommended to always use quit to end the session

driver.quit();
/examples/java/src/test/java/dev/selenium/getting_started/FirstScript.java
packagedev.selenium.getting_started;importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.chrome.ChromeDriver;importjava.time.Duration;publicclass FirstScript{publicstaticvoidmain(String[]args){WebDriverdriver=newChromeDriver();driver.get("https://www.selenium.dev/selenium/web/web-form.html");driver.getTitle();driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));WebElementtextBox=driver.findElement(By.name("my-text"));WebElementsubmitButton=driver.findElement(By.cssSelector("button"));textBox.sendKeys("Selenium");submitButton.click();WebElementmessage=driver.findElement(By.id("message"));message.getText();driver.quit();}}
 driver.quit()
/examples/python/tests/drivers/test_options.py
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
 driver.Quit();
/examples/dotnet/SeleniumDocs/GettingStarted/FirstScript.cs
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace SeleniumDocs.GettingStarted;
public static class FirstScript
{
 public static void Main()
 {
 IWebDriver driver = new ChromeDriver();
 driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");
 var title = driver.Title;
 driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
 var textBox = driver.FindElement(By.Name("my-text"));
 var submitButton = driver.FindElement(By.TagName("button"));
 textBox.SendKeys("Selenium");
 submitButton.Click();
 var message = driver.FindElement(By.Id("message"));
 var value = message.Text;
 driver.Quit();
 }
}
 driver.quit
/examples/ruby/spec/drivers/options_spec.rb
# 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
 await driver.quit();
/examples/javascript/test/getting_started/firstScript.spec.js
const {By, Builder, Browser} = require('selenium-webdriver');
const assert = require("assert");
(async function firstTest() {
 let driver;
 try {
 driver = await new Builder().forBrowser(Browser.CHROME).build();
 await driver.get('https://www.selenium.dev/selenium/web/web-form.html');
 let title = await driver.getTitle();
 assert.equal("Web form", title);
 await driver.manage().setTimeouts({implicit: 500});
 let textBox = await driver.findElement(By.name('my-text'));
 let submitButton = await driver.findElement(By.css('button'));
 await textBox.sendKeys('Selenium');
 await submitButton.click();
 let message = await driver.findElement(By.id('message'));
 let value = await message.getText();
 assert.equal("Received!", value);
 } catch (e) {
 console.log(e)
 } finally {
 await driver.quit();
 }
}())
 driver.quit()
/examples/kotlin/src/test/kotlin/dev/selenium/getting_started/FirstScriptTest.kt
package dev.selenium.getting_started
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import java.time.Duration
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class FirstScriptTest {
 private lateinit var driver: WebDriver
 @Test
 fun eightComponents() {
 driver = ChromeDriver()
 driver.get("https://www.selenium.dev/selenium/web/web-form.html")
 val title = driver.title
 assertEquals("Web form", title)
 driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500))
 var textBox = driver.findElement(By.name("my-text"))
 val submitButton = driver.findElement(By.cssSelector("button"))
 textBox.sendKeys("Selenium")
 submitButton.click()
 val message = driver.findElement(By.id("message"))
 val value = message.getText()
 assertEquals("Received!", value)
 driver.quit()
 }
}