Friday 12 July 2013

Webdriver example program

Naukri Login:



import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;

public class Login {
public static void main(String args[]) throws InterruptedException {

//Launches the firefox browser
WebDriver driver = new FirefoxDriver();
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

                // Loads the Naukri application
driver.get("http://www.naukri.com/");

                // Maximize the browser
                driver.manage().window().maximize();
                // Prints the title of the naukri application
System.out.println(driver.getTitle());
 
                // Enters the username
driver.findElement(By.id("username")).sendKeys("tester@gmail.com");

                // Enters the username
driver.findElement(By.id("password")).sendKeys("tester");

                // Clicks on the login button
driver.findElement(By.name("Login")).click();
Thread.sleep(8000); // Using sleep() is not a good practice, we need to use explicit wait, will see about this in later post

               // Stores the username displayed in the home page into the variable 'actual'
String actual = driver.findElement(By.id("nameDisplaySpan")).getText(); 
System.out.println("actual: "+actual);

                // Clicks on the log out link
driver.findElement(By.linkText("LogOut")).click();


                // Close the browser
                driver.close();

                // Quit the driver session
driver.quit();
}

}

3 comments:


  1. Best place to learn Appium Android IOS Automation Testing Training in Chennai

    Go for Appium training in chennai for real time mobile automation testing training with real time project support.
    Mr. Vishwa is a best person who can teach and develop people in Appium and Selenium,Coded UI Automation Tools with real time scenarios You can contact 8122241286 for Best APPIUM and selenium Training in Chennai

    ReplyDelete
  2. Appium Training in chennai
    We provides Best Appium Training in Chennai with real time project assistance by our leading Appium mobile App Automation testing architect
    For Free Live Demo @ Call to 8122241286.
    Appium ,Selenium,Mobile Automation Testiing using Android and IOS
    www.thecreatingexperts.com
    Appium training in chennai

    ReplyDelete