Selenium Webdriver – Automation with Java

By | 13/12/2012


One of the most used language to write Selenium Webdriver script is Java. you can find a basic simple Java class to run Selenium Webdriver.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SimpleSeleniumTest {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();


String element = driver.findElement(By.xpath("//a[@class='site-description']")).getText();

System.out.println("Page title is: " + driver.getTitle());

System.out.println("Site Description is: " + element);

//Close the browser


after you run your code, you should see following output:

Page title is: Software Test Engineering – Test Automation | A Blog For Software Testing and Automation
Site Description is: A Blog For Software Testing and Automation

Leave a Reply

Your email address will not be published. Required fields are marked *