Create new Maven project

Screen Shot 2017-01-22 at 10.11.52 AM.png

Screen Shot 2017-01-22 at 10.12.34 AM.png

Add Selenium to pom file

<modelVersion>4.0.0</modelVersion>

<groupId>Selenium2</groupId>
<artifactId>Selenium2</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.0.1</version>
    </dependency>
</dependencies>

Then add

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class HelloSelenium {

    static WebDriver driver;

    public static void main(String[] args) throws Exception {
        // Optional, if not specified, WebDriver will search your path for chromedriver.
        System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com/xhtml");
        Thread.sleep(5000);  // Let the user actually see something!
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("ChromeDriver");
        searchBox.submit();
        Thread.sleep(5000);  // Let the user actually see something!
        driver.quit();
    }
}

Go to this site

https://sites.google.com/a/chromium.org/chromedriver/getting-started

 

and download the ChromeDriver

Screen Shot 2017-01-22 at 10.22.34 AM.png

Screen Shot 2017-01-22 at 10.22.57 AM.png

Unzip it

Screen Shot 2017-01-22 at 10.23.22 AM.png

This specify it’s path in the above file where it says

/path/to/chromedriver

i.e.

/Users/jr/Downloads/chromedriver

If you run you should now see

Screen Shot 2017-01-22 at 10.26.17 AM.png

And a remote control google happen in the background.

Screen Shot 2017-01-22 at 10.26.59 AM.png