First Test Case with Selenium WebDriver












package mypackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Firstscript {

 public static void main(String[] args) throws InterruptedException {
  // TODO Auto-generated method stub
        
  //Set the path of the driver
  String exepath = "C:\\Users\\Amit\\Downloads\\geckodriver-v0.19.1-win64//geckodriver.exe";
  System.setProperty("webdriver.gecko.driver", exepath);
  
  WebDriver driver = new FirefoxDriver ();
  
  //Open URL
  driver.get("https://www.facebook.com/");
  
  
  driver.findElement(By.id("u_0_l")).sendKeys("testing");
  driver.findElement(By.id("u_0_n")).sendKeys("treasure");
  driver.findElement(By.id("u_0_q")).sendKeys("9988778899");
  driver.findElement(By.id("u_0_x")).sendKeys("Testingtreasure");
  
  //Drop down list
  Select sel1 = new Select (driver.findElement(By.id("day")));
  sel1.selectByValue("1");
  
  Select sel2 = new Select (driver.findElement(By.id("month")));
  sel2.selectByValue("2");
  
  Select sel3 = new Select (driver.findElement(By.id("year")));
  sel3.selectByValue("1991");
  
  //Wait command
  Thread.sleep(4000);
  
  //Radio button
  WebElement radiobtn = driver.findElement(By.id("u_0_9"));
  radiobtn.click();
  
  //click on button
  driver.findElement(By.id("u_0_13")).click();
  
  
 }

}


0 comments:

Post a Comment