Google Chrome Driver: Difference between revisions
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
=Controlling a Chrome Browser from Java= | =Controlling a Chrome Browser from Java= | ||
A Java program can control a browser via the Chrome driver: | A Java program can control a browser via the Chrome driver: | ||
<syntaxhighlight lang='java'> | |||
import org.openqa.selenium.*; | |||
import org.openqa.selenium.chrome.*; | |||
public class Main { | |||
public static void main(String[] args) throws Exception { | |||
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver"); | |||
WebDriver driver = new ChromeDriver(); | |||
driver.get("http://www.google.com/"); | |||
WebElement searchBox = driver.findElement(By.name("q")); | |||
searchBox.sendKeys("ChromeDriver"); | |||
searchBox.submit(); | |||
driver.quit(); | |||
} | |||
} | |||
</syntaxhighlight> | |||
Playground project: {{External|https://github.com/ovidiuf/playground/tree/master/selenium/chromedriver/chromedriver-java}} | |||
More examples: {{External|https://sites.google.com/chromium.org/driver/getting-started}} | |||
=Operations= | =Operations= |
Revision as of 07:36, 2 June 2021
External
Internal
Overview
ChromeDriver is a separate executable that Selenium WebDriver uses to control Chrome.
The executable is chromedriver
. ChromeDriver expects you to have Chrome installed in the default location for your platform. ChromeDriver can be forced to use a custom location, by setting a special capability (TODO: https://sites.google.com/chromium.org/driver/capabilities)
Controlling a Chrome Browser from Java
A Java program can control a browser via the Chrome driver:
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
public class Main {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com/");
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
driver.quit();
}
}
Playground project:
More examples:
Operations
Installation
Mac
brew install --cask chromedriver
brew upgrade --cask chromedriver
Version
chromedriver --version