0

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"

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

5 Answers 5

3

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')]

1

Try with the below xpath.

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

Try this below XPath.

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

Prefer Relative XPath rather than Absolute XPath.

0
0

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

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

Try this below code.

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

This should also work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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