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();
}
}