Wednesday, June 25, 2014

Login/logout scenario for linkedin.

Note: Please give the your user id and password in highlighted place.

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) throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.linkedin.com/");
driver.findElement(By.id("session_key-login")).sendKeys("give_ur_userid_here");
driver.findElement(By.id("session_password-login")).sendKeys("give_ur_pass_here");
//driver.findElement(By.xpath("//input[@id='signin']")).click();
Actions act=new Actions(driver);
WebElement sign = driver.findElement(By.id("signin"));
act.moveToElement(sign).doubleClick().perform();
WebElement network = driver.findElement(By.xpath("//li[@class='nav-item']/a[contains(text(),'Connections')]"));
act.moveToElement(network).perform();
Thread.sleep(1000);
WebElement addConn = driver.findElement(By.xpath("//ul[@class='sub-nav']//a[contains(text(),'Add Connections')]"));
act.moveToElement(addConn).click().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();

}
}

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) throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.linkedin.com/");
driver.findElement(By.id("session_key-login")).sendKeys("give_ur_userid_here");
driver.findElement(By.id("session_password-login")).sendKeys("give_ur_pass_here");
//driver.findElement(By.xpath("//input[@id='signin']")).click();
Actions act=new Actions(driver);
WebElement sign = driver.findElement(By.id("signin"));
act.moveToElement(sign).doubleClick().perform();
WebElement network = driver.findElement(By.xpath("//li[@class='nav-item']/a[contains(text(),'Connections')]"));
act.moveToElement(network).perform();
Thread.sleep(1000);
WebElement addConn = driver.findElement(By.xpath("//ul[@class='sub-nav']//a[contains(text(),'Add Connections')]"));
act.moveToElement(addConn).click().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();

}
}

2 comments: