Try to sign out from LinkedIn page using Selenium Webdriver

913 views
Skip to first unread message

Milo Haireche

unread,
Dec 29, 2013, 5:12:06 PM12/29/13
to seleniu...@googlegroups.com
Hello to you all;

I am a beginner in Selenium webdriver. I am trying to automate the LinkedIn page using selenium webdriver. Below is my code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Login {

    public static void main(String[] args) throws InterruptedException {
   
       
        System.out.println("My name is Milo and I am testing Selenium WebDriver.");
       
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.linkedin.com");
        System.out.println(driver.getTitle());
        System.out.println(driver.getCurrentUrl());
       
        // Sign in to LinkedIn with Email Address and Password
        WebElement emailAddress = driver.findElement(By.xpath("//*[@id='session_key-login']"));
        emailAddress.sendKeys("xxxxx...@xxx.com");
       
        WebElement Password = driver.findElement(By.xpath("//*[@id='session_password-login']"));
        Password.sendKeys("xxxxxxxxxxxxxx");
       
        driver.findElement(By.xpath("//*[@id='signin']")).click();
        System.out.println(driver.getCurrentUrl());
       
        // Hold the program for 8 seconds
        Thread.sleep(8000L);
       
        // Sign out from LinkedIn    
        driver.findElement(By.xpath("//*[@id='img-defer-id-1-56424']")).click();
        driver.findElement(By.xpath("//*[@id='account-sub-nav']/div/div[2]/ul/li[1]/div/span/span[3]/a")).click();



Here is the console result:
--------------------------------------

My name is Milo and I am testing Selenium WebDriver.
World's Largest Professional Network | LinkedIn
https://www.linkedin.com/
http://www.linkedin.com/nhome/?trk=


Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='img-defer-id-1-56424']"}
Command duration or timeout: 59 milliseconds

Shadaab

unread,
Dec 30, 2013, 1:50:27 AM12/30/13
to seleniu...@googlegroups.com
Modify your code and try with this one...

 // Sign out from LinkedIn    

Actions action = new Actions(driver);
WebElement mouseOverTo = driver.findElement(By.xpath("//*[@id='control_gen_5']/li[4]/a"));
action.moveToElement(mouseOverTo).build().perform();
                   wait(2000)
        driver.findElement(By.xpath(".//*[@id='account-sub-nav']/div/div[2]/ul/li[1]/div/span/span[3]/a")).click();


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d51c5a21-c990-459a-b56b-ec804c6cebab%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ranjith R Reddy

unread,
Dec 30, 2013, 1:06:52 PM12/30/13
to seleniu...@googlegroups.com
i hope their will be problem with xpaths so cross check it with xpath cheaker

Oscar Rieken

unread,
Dec 30, 2013, 1:22:39 PM12/30/13
to seleniu...@googlegroups.com
unless you work for linkedin then you are violating their ToS 


On Mon, Dec 30, 2013 at 1:06 PM, Ranjith R Reddy <ranjith...@gmail.com> wrote:
i hope their will be problem with xpaths so cross check it with xpath cheaker

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

nani.thrinath.info

unread,
Dec 31, 2013, 8:36:57 AM12/31/13
to seleniu...@googlegroups.com
Try this

 driver.get("http://linkedin.com");
 driver.findElement(By.id("session_key-login")).sendKeys("ABC");
 driver.findElement(By.id("session_password-login")).sendKeys("XYZ");
 driver.findElement(By.id("signin")).click();
 WebElement element = driver.findElement(By.xpath("//*[@id='control_gen_5']/li[4]/a/img"));
 action.moveToElement(element).build().perform();
 Thread.sleep(2000);
 driver.findElement(By.linkText("Sign Out")).click();

Thrinath



For more options, visit https://groups.google.com/groups/opt_out.



--
Thrinath
Reply all
Reply to author
Forward
0 new messages