Saturday, May 31, 2014

Linked in signin and sign out.

import java.util.Scanner;
import java.util.concurrent.TimeUnit;

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.interactions.Actions;

public class LinkedIn {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("enter ur user id: ");
        String userId = in.nextLine();
        System.out.println("enter ur pass: ");
        String pass = in.nextLine();
       
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.linkedin.com/?trk=nav_logo");
        //login
        driver.findElement(By.id("session_key-login")).sendKeys(userId);
        driver.findElement(By.id("session_password-login")).sendKeys(pass);
        System.out.println(driver.findElement(By.id("session_password-login")).getAttribute("type"));
        Actions act = new Actions(driver);
        WebElement sign = driver.findElement(By.id("signin"));
        act.moveToElement(sign).doubleClick().perform();
       
        WebElement img = driver.findElement(By.xpath("//img[@class='img-defer nav-profile-photo']"));
        act.moveToElement(img).perform();
        WebElement signOut = driver.findElement(By.xpath("//a[contains(text(),'Sign Out')]"));
        act.moveToElement(signOut).click().perform();
    }
}

No comments:

Post a Comment