I am unable to click on logout link in my web page using XPath.

XPath: html/body/div[1]/span/div[1]/a[1]

I See my code in an attachment:

my Code .

HTML Script for "logout"

  • //a[contains(text(),'[Logout]')] - This XPath will definitely works for you. – Bharat Mane Jun 29 at 11:25
  • Try to wait for the webelement by using WebDriverWait class. – Alok Jul 1 at 7:07

Switch to the iframe first, for that try the below code.

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[src*=sfactory]")));

After that you can use the XPath or CSS selector to identify the locator.

css: a[onclick*=exitAction]

xpath: //a[contains(@onclick, 'exitAction')]

Try with the below xpath.

//a[contains(text(),'Logout')] 

Try this below XPath.

//a[contains(text(),'[Logout]')]

Prefer Relative XPath rather than Absolute XPath.

Try the below code using LinkText locator for locating the logout button.

driver.findElementBy.linkText("[Logout]")

Try this below code.

//a[contains(.,'Logout')]

This should also work.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.