Unable to click on Facebook logout button.

I m trying to logout facebook using selenium webDriver but I am not able to click on logout although rest of the code is working fine.
Please help me!
Below is the Code:

package Basics;

import java.util.Set;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class FBCheckManually {

public static void main(String args[]) throws Exception
{
WebDriver driver;
//        System.setProperty(“webdriver.chrome.driver”,”C:/selenium\\chromedriver.exe”);
//         driver=new ChromeDriver();
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(“https://www.facebook.com/”);
assertTrue(driver.findElement(By.cssSelector(“BODY”)).getText().matches(“^[\\s\\S]*Email or Phone[\\s\\S]*$”));
assertTrue(driver.findElement(By.cssSelector(“BODY”)).getText().matches(“^[\\s\\S]*Password[\\s\\S]*$”));
driver.findElement(By.cssSelector(“input.inputtext”)).clear();
driver.findElement(By.cssSelector(“input.inputtext”)).sendKeys(“test779”);
driver.findElement(By.id(“pass”)).clear();
driver.findElement(By.id(“pass”)).sendKeys(“Pss123”);
driver.findElement(By.id(“u_0_w”)).click();
assertTrue(driver.findElement(By.cssSelector(“BODY”)).getText().matches(“^[\\s\\S]*Shai test[\\s\\S]*$”));
System.out.println(“user logged in successfully”);
driver.findElement(By.id(“userNavigationLabel”)).click();
Thread.sleep(3000);
//facing Issue in below line(unable to click on logout)
driver.findElement(By.xpath(“.//span[contains(@class,’_54nh’)]/form”)).click();
assertEquals(driver.getTitle(), “Facebook – Log In or Sign Up”);
System.out.println(“user loged out successfully”);

}

}

Default Asked on March 22, 2016 in Selenium WebDriver.

Remove that . before span and try

on April 7, 2016.

still not working

on April 10, 2016.

first try to locate the element with the xpath you are trying ,
then implement

on April 20, 2016.
Add Comment
  • 5 Answer(s)

    First click on dropdown(.//*[@id=’userNavigationLabel’]) and then click on logout link

    Default Answered on April 3, 2016.
    Add Comment

    This is already used in my code using
    driver.findElement(By.id(“userNavigationLabel”)).click();

    but after clicking on a pop up is generated but unable to click on log out by below code:
    driver.findElement(By.xpath(“.//span[contains(@class,’_54nh’)]/form”)).click();

    Default Answered on April 10, 2016.
    Add Comment

    use this for clicking logout:
    driver.findElement(By.xpath(“//li[12]/a/span/span”)).click();

    Train Answered on April 18, 2016.
    Add Comment

    Yes i am also facing the same issue, did you get the solution?

    Default Answered on August 10, 2016.
    Add Comment

    hey hi, Here is the solution for this…
    Try executing with this you will get success…

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.findElement(By.xpath(“//li[12]/a/span/span”)).click();

    Default Answered on August 10, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.