Scenario is to Login to facebook account and then logout. I tried using xpath className and id. But everytime it shows error as ElementNotfound or element not visible. Later I Checked it using SELENIUM IDE and got this xpath for the LOGOUT link. But still the error persists. Kindly help me.
public class FacebookLogin {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
Thread.sleep(2000);
WebElement username = driver.findElement(By.id("email"));
WebElement password = driver.findElement(By.id("pass"));
WebElement Login = driver.findElement(By.id("u_0_v"));
username.sendKeys("myusername@xyz.com");
password.sendKeys("mypassword");
Login.click();
Thread.sleep(2000);
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement navigationclick = driver.findElement(By.id("logoutMenu"));
WebElement logout = driver.findElement(By.xpath("//div[@id='u_d_1']/div/div/div/div/div/ul/li[12]/a/span/span"));
navigationclick.click();
if(logout.isEnabled() && logout.isDisplayed()) {
logout.click();
}
else {
System.out.println("Element not found");
}
}
}
HTML CODE FOR LOG OUT Log Out
This code solved the issue for Logout from Facebook:
WORKING:
You can use JavascriptExecutor to click on logout after login to system
Get back to me if you are still facing problem
Python code for facebook logout using selenium
Using the CSS selector method, select the logout element using the class "._w0d" and attribute for action="https://www.facebook.com/logout.php". This being a form, should be submitted, thus use the "submit" method.
code for facebook loging and logout : (working)