Driver Service Class

The Service classes are for managing the starting and stopping of drivers. They can not be used with a Remote WebDriver session.

Service classes allow you to specify information about the driver, like location and which port to use. They also let you specify what arguments get passed to the command line. Most of the useful arguments are related to logging.

Default Service instance

To start a driver with a default service instance:

ChromeDriverService service = new ChromeDriverService.Builder().build();
WebDriver driver = new ChromeDriver(service);
from selenium.webdriver.chrome.service import Service
from selenium import webdriver

service = Service()
driver = webdriver.Chrome(service=service)
service = Selenium::WebDriver::Service.chrome
driver = Selenium::WebDriver.for :chrome, service: service

Driver location

Note: If you are using Selenium 4.6 or greater, you shouldn’t need to set a driver location. If you can not update Selenium or have an advanced use case here is how to specify the driver location:

In Java you can also set the driver location with a System Property:

System.setProperty("webdriver.chrome.driver", driver_location);

Otherwise:

ChromeDriverService service = new ChromeDriverService.Builder()
    .usingDriverExecutable(driverLocation)
    .build();

ChromeDriver driver = new ChromeDriver(service);
from selenium.webdriver.chrome.service import Service
from selenium import webdriver

service = Service(executable_path=driver_location)
driver = webdriver.Chrome(service=service)
var driver = new ChromeDriver(driverLocation);
service = Selenium::WebDriver::Service.chrome(path: driver_location)
driver = Selenium::WebDriver.for :chrome, service: service
const {Builder} = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

const service = new chrome.ServiceBuilder(driverLocation);
const driver = new Builder().forBrowser('chrome').setChromeService(service).build();
import org.openqa.selenium.chrome.ChromeDriver

fun main(args: Array<String>) {
    System.setProperty("webdriver.chrome.driver", driverLocation)
    val driver = ChromeDriver()
}

Driver port

Setting log output

Console output

File output