Wednesday, July 29, 2015

Selenium login code

package com.scm.test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class RegistrationTest {
   
public static void main(String[] args) {
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
//  Wait For Page To Load

// Navigate to URL
driver.get("http://192.168.1.1/");
// Maximize the window.
driver.manage().window().maximize();
// Enter UserName
driver.findElement(By.id("username")).sendKeys("admin");
// Enter Password
driver.findElement(By.id("password")).sendKeys("password");
// Wait For Page To Load
// Click on 'Sign In' button
driver.findElement(By.id("loginBtn")).click();
//Click on Compose Mail.
driver.findElement(By.xpath("//div[@class='z0']/div")).click();

//Close the browser.
driver.close();
}
}