Basic Selenium Web Driver Program using Java

                           The most basic thing we have to do is to select an element and display the title of the article or a page.Let us display the title or contents of our website using a simple java program using selenium.
                           You need to know basics of  how to use eclipse and how to add libraries(jar) files to your eclipse Java project.
1.Open eclipse ,create a Java project and add selenium jar to your build path.
2.Make sure you have added all the jars that come when you downloaded the Selenium.
3.You have Firefox installed as we will be using Firefox driver.
3.Create a new class and add the below code to your class.



package com.selenium_basics;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class FirstSeleniumProgram {

 // for more visit http://learn-selenium-easy.blogspot.com
 
 @Test 
 public void displayTitle() throws InterruptedException{
 
  WebDriver driver=new FirefoxDriver();
  driver.get("http://learn-selenium-easy.blogspot.in/2016/02/what-is-selenium.html");
  Thread.sleep(1000);
  WebElement post_title=driver.findElement(By.xpath("//*[@id='Blog1']/div[1]/div/div/div/div[1]/h3"));
  System.out.println(post_title.getText());
  WebElement post_content=driver.findElement(By.xpath("/html/body/div[3]/div[2]/div/div/div[1]/div/div/div/div[1]/div[2]/div[1]"));
  System.out.println(post_content.getText());
  
  driver.close();
  driver.quit();
 }
}

4.Make sure there are no errors and run the program as TestNg test case.
5.You can view the out put in the console tab in your eclipse.

Sample Output:-
Sample Output

 Thank you!