Friday, May 23, 2014

How to login in linkedIn

Note- After login, 1st move cursor over Connections then click on Add Connections.

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);
        Actions act = new Actions(driver);
        WebElement sign = driver.findElement(By.id("signin"));
        act.moveToElement(sign).doubleClick().perform();
     
        //1st move cursor over Connections then click on Add Connections
      
        WebElement network = driver.findElement(By.xpath("//li[@class='nav-item']/a[contains(text(),'Connections')]"));
        act.moveToElement(network).perform();
        driver.findElement(By.xpath("//ul[@class='sub-nav']//a[contains(text(),'Add Connections')]")).click();
      
        //signout
        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();
      
        driver.quit();
    }
}

2 comments:

  1. Hello Sanjay, currently I have 3 programs running properly in same project,
    but when i tried to check above programs for linked in.
    then it gives me exception in main error
    kindly tell me how do i deal with that.

    ReplyDelete
    Replies
    1. Yes Vishal , you are right. Actually Linkedin page has been changed. Previously there was 'Network' option in main menu but now they have changed it to 'Connections'.
      I have corrected the script. Please check copy paste it again and try to execute.
      Let me know if you face any issue.
      Thanks for pointing out this.

      Delete