Package org.openqa.selenium.chrome
Class ChromeDriver
- java.lang.Object
-
- org.openqa.selenium.remote.RemoteWebDriver
-
- org.openqa.selenium.chromium.ChromiumDriver
-
- org.openqa.selenium.chrome.ChromeDriver
-
- All Implemented Interfaces:
org.openqa.selenium.devtools.HasDevTools
,org.openqa.selenium.HasAuthentication
,org.openqa.selenium.HasCapabilities
,org.openqa.selenium.html5.LocationContext
,org.openqa.selenium.html5.WebStorage
,org.openqa.selenium.interactions.HasInputDevices
,org.openqa.selenium.interactions.HasTouchScreen
,org.openqa.selenium.interactions.Interactive
,org.openqa.selenium.JavascriptExecutor
,org.openqa.selenium.logging.HasLogEvents
,org.openqa.selenium.mobile.NetworkConnection
,org.openqa.selenium.SearchContext
,org.openqa.selenium.TakesScreenshot
,org.openqa.selenium.virtualauthenticator.HasVirtualAuthenticator
,org.openqa.selenium.WebDriver
public class ChromeDriver extends org.openqa.selenium.chromium.ChromiumDriver
AWebDriver
implementation that controls a Chrome browser running on the local machine. This class is provided as a convenience for easily testing the Chrome browser. The control server which each instance communicates with will live and die with the instance. To avoid unnecessarily restarting the ChromeDriver server with each instance, use aRemoteWebDriver
coupled with the desiredChromeDriverService
, which is managed separately. For example:
Note that unlike ChromeDriver, RemoteWebDriver doesn't directly implement role interfaces such asimport static org.junit.Assert.assertEquals; import org.junit.*; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.openqa.selenium.chrome.ChromeDriverService; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; {@literal @RunWith(JUnit4.class)} public class ChromeTest extends TestCase { private static ChromeDriverService service; private WebDriver driver; {@literal @BeforeClass} public static void createAndStartService() { service = new ChromeDriverService.Builder() .usingDriverExecutable(new File("path/to/my/chromedriver.exe")) .usingAnyFreePort() .build(); service.start(); } {@literal @AfterClass} public static void createAndStopService() { service.stop(); } {@literal @Before} public void createDriver() { driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); } {@literal @After} public void quitDriver() { driver.quit(); } {@literal @Test} public void testGoogleSearch() { driver.get("http://www.google.com"); WebElement searchBox = driver.findElement(By.name("q")); searchBox.sendKeys("webdriver"); searchBox.quit(); assertEquals("webdriver - Google Search", driver.getTitle()); } }
LocationContext
andWebStorage
. Therefore, to access that functionality, it needs to beaugmented
and then cast to the appropriate interface.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openqa.selenium.remote.RemoteWebDriver
org.openqa.selenium.remote.RemoteWebDriver.RemoteTargetLocator, org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriverOptions, org.openqa.selenium.remote.RemoteWebDriver.When
-
Nested classes/interfaces inherited from interface org.openqa.selenium.mobile.NetworkConnection
org.openqa.selenium.mobile.NetworkConnection.ConnectionType
-
Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
org.openqa.selenium.WebDriver.ImeHandler, org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window
-
-
Constructor Summary
Constructors Constructor Description ChromeDriver()
Creates a new ChromeDriver using thedefault
server configuration.ChromeDriver(org.openqa.selenium.Capabilities capabilities)
Deprecated.ChromeDriver(ChromeDriverService service)
Creates a new ChromeDriver instance.ChromeDriver(ChromeDriverService service, org.openqa.selenium.Capabilities capabilities)
ChromeDriver(ChromeDriverService service, ChromeOptions options)
Creates a new ChromeDriver instance with the specified options.ChromeDriver(ChromeOptions options)
Creates a new ChromeDriver instance with the specified options.
-
Method Summary
-
Methods inherited from class org.openqa.selenium.chromium.ChromiumDriver
executeCdpCommand, getCastIssueMessage, getCastSinks, getDevTools, getLocalStorage, getNetworkConnection, getSessionStorage, getTouch, launchApp, location, onLogEvent, quit, register, selectCastSink, setFileDetector, setLocation, setNetworkConnection, setPermission, startTabMirroring, stopCasting
-
Methods inherited from class org.openqa.selenium.remote.RemoteWebDriver
addVirtualAuthenticator, builder, close, execute, execute, execute, executeAsyncScript, executeScript, findElement, findElement, findElements, findElements, get, getCapabilities, getCommandExecutor, getCurrentUrl, getElementConverter, getErrorHandler, getExecuteMethod, getFileDetector, getKeyboard, getMouse, getPageSource, getScreenshotAs, getSessionId, getTitle, getWindowHandle, getWindowHandles, log, manage, navigate, perform, removeVirtualAuthenticator, resetInputState, setCommandExecutor, setElementConverter, setErrorHandler, setFoundBy, setLogLevel, setSessionId, startSession, switchTo, toString
-
-
-
-
Constructor Detail
-
ChromeDriver
public ChromeDriver()
Creates a new ChromeDriver using thedefault
server configuration.
-
ChromeDriver
public ChromeDriver(ChromeDriverService service)
Creates a new ChromeDriver instance. Theservice
will be started along with the driver, and shutdown upon callingChromiumDriver.quit()
.- Parameters:
service
- The service to use.- See Also:
RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)
-
ChromeDriver
@Deprecated public ChromeDriver(org.openqa.selenium.Capabilities capabilities)
Deprecated.Creates a new ChromeDriver instance. Thecapabilities
will be passed to the ChromeDriver service.- Parameters:
capabilities
- The capabilities required from the ChromeDriver.- See Also:
ChromeDriver(ChromeDriverService, Capabilities)
-
ChromeDriver
public ChromeDriver(ChromeOptions options)
Creates a new ChromeDriver instance with the specified options.- Parameters:
options
- The options to use.- See Also:
ChromeDriver(ChromeDriverService, ChromeOptions)
-
ChromeDriver
public ChromeDriver(ChromeDriverService service, ChromeOptions options)
Creates a new ChromeDriver instance with the specified options. Theservice
will be started along with the driver, and shutdown upon callingChromiumDriver.quit()
.- Parameters:
service
- The service to use.options
- The options to use.
-
ChromeDriver
@Deprecated public ChromeDriver(ChromeDriverService service, org.openqa.selenium.Capabilities capabilities)
Deprecated.Creates a new ChromeDriver instance. Theservice
will be started along with the driver, and shutdown upon callingChromiumDriver.quit()
.- Parameters:
service
- The service to use.capabilities
- The capabilities required from the ChromeDriver.
-
-