rpgs_player
rpgs_player

Reputation: 5449

Selenium WebDriver Log Out from Facebook

Does anyone know how to click log out button? I tried using driver.findElement(By.linkText("Log out"));

But it returned an error saying element is not found. Is it because the list is dynamically generated?

Upvotes: 1

Views: 1041

Answers (2)

Saurabh Gaur
Saurabh Gaur

Reputation: 23815

You should try using WebDriverWait to wait until elementToBeClickable it works for me as below :-

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement accountSettings = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Account Settings")));
accountSettings.click() //this will click on setting link to open menu

WebElement logOut = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Log Out")));
logOut.click() // this will click on logout link

Hope it helps...:)

Upvotes: 5

noor
noor

Reputation: 3004

I assume, after click on arrow button, Log Out button appers in ur code. So to click on that log Out button, use the below portion as cssSelector:

a[data-gt*='menu_logout']>span>span._54nh

driver.findElement(By.cssSelector("a[data-gt*='menu_logout']>span>span._54nh"));

Upvotes: 0

Related Questions