Class ChromeDriver

  • All Implemented Interfaces:
    org.openqa.selenium.devtools.HasDevTools, 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.internal.FindsByClassName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.mobile.NetworkConnection, org.openqa.selenium.SearchContext, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.WebDriver

    public class ChromeDriver
    extends org.openqa.selenium.chromium.ChromiumDriver
    A WebDriver 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 a RemoteWebDriver coupled with the desired ChromeDriverService, which is managed separately. For example:
    
    
     import 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());
       }
     }
     
    Note that unlike ChromeDriver, RemoteWebDriver doesn't directly implement role interfaces such as LocationContext and WebStorage. Therefore, to access that functionality, it needs to be augmented and then cast to the appropriate interface.
    See Also:
    ChromeDriverService.createDefaultService()
    • 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
    • Method Summary

      • Methods inherited from class org.openqa.selenium.chromium.ChromiumDriver

        executeCdpCommand, getCastIssueMessage, getCastSinks, getDevTools, getLocalStorage, getNetworkConnection, getSessionStorage, getTouch, launchApp, location, quit, selectCastSink, setFileDetector, setLocation, setNetworkConnection, setPermission, startTabMirroring, stopCasting
      • Methods inherited from class org.openqa.selenium.remote.RemoteWebDriver

        builder, close, execute, execute, executeAsyncScript, executeScript, findElement, findElement, findElementByClassName, findElementByCssSelector, findElementById, findElementByLinkText, findElementByName, findElementByPartialLinkText, findElementByTagName, findElementByXPath, findElements, findElements, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByLinkText, findElementsByName, findElementsByPartialLinkText, findElementsByTagName, findElementsByXPath, get, getCapabilities, getCommandExecutor, getCurrentUrl, getElementConverter, getErrorHandler, getExecuteMethod, getFileDetector, getKeyboard, getMouse, getPageSource, getScreenshotAs, getSessionId, getTitle, getWindowHandle, getWindowHandles, log, manage, navigate, perform, resetInputState, setCommandExecutor, setElementConverter, setErrorHandler, setFoundBy, setLogLevel, setSessionId, startSession, switchTo, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait