Getting Started With Selenium : Part 2

In the previous post we have setup our selenium environment. Now we can write our first selenium script.

1. In the Project Explorer Right click package 'com' which was created earlier. And create a class Inside it.

3. Now In the editor copy and paste the code.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com;

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

public class Test1 {

 public static void main(String[] args) throws Exception {

  System.setProperty("webdriver.chrome.driver", "drivers/chromedriver.exe");

  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();

 }

}

Click the run button in IDE execute the file.

Comments