Linked Questions

Popular Questions

How to logout of Facebook using selenium.WebDriver and HtmlUnitDriver

Asked by At

I am using selenium.WebDriver and HtmlUnitDriver to login to Facebook, but I can't logout.

public static void main(String[] args) throws InterruptedException {

WebDriver driver = new HtmlUnitDriver();
System.out.println("Title of the page "+ driver.getTitle());
WebElement username = driver.findElement("email"));
username.sendKeys("[email protected]"); 
WebElement password = driver.findElement("pass"));
WebElement Signup_button = driver.findElement("loginbutton"));;
System.out.println("After login title is = " + driver.getTitle());

Until now it works. And The following steps cover the logout part (not working):

WebElement logOut = driver.findElement("userNavigationLabel"));;
WebElement signOut = driver.findElement("Log Out"));;

System.out.println("Logged Out Successfully!!!!!!!!!!!!!!!!!!!");
String pagetitle = driver.getTitle();



Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element with name: Log Out

Facebook Logout html code

<span><span class="_54nh"><form class="_w0d"
 action="" data-nocookies="1" 
id="show_me_how_logout_1" method="post" onsubmit="return window.Event
 &amp;&amp; Event.__inlineSubmit &amp;&amp; 
Event.__inlineSubmit(this,event)"><input name="fb_dtsg" 
value="AQGzvtPjFD1W:AQFslBEMcQG9" autocomplete="off" type="hidden"><input
 autocomplete="off" name="ref" value="mb" type="hidden"><input 
autocomplete="off" name="h" value="AfeziZXPRhN6ncxD" type="hidden">
</form>Log Out</span></span>

I have also tried this Code by Saurabh Gaur Selenium WebDriver Log Out from Facebook

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement accountSettings = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Account Settings"))); //this will click on setting link to open menu
WebElement logOut = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Log Out"))); // this will click on logout link


Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for element to be clickable: By.linkText: Log Out
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: xxxxxxxxxxx java.version: '1.8.0_101'
Driver info: driver.version: unknown
    at HtmlDemoProgram1.main(
Caused by: org.openqa.selenium.NoSuchElementException: No link found with text: Log Out
For documentation on this error, please visit:

Related Questions