enter image description here

I am trying to find out XPath for this "Sign Out" button, can anyone help me?

  • What have you tried? I would use the a with the title attribute but we don't usually write out the specific code for you on this site Commented Jul 6, 2017 at 14:16
  • Do note that its very important to try pick up good habits as using css selectors(your own mind you,not necessarily the ones your browser dev tools give you) instead of copy/pasting xpaths that may break with any design change of your page.
    – Leon
    Commented Jul 7, 2017 at 11:45

4 Answers 4


There are much better ways to locate the element aside from using XPath, don't focus on XPath too much - this is, generally speaking, the slowest and the least readable way to locate elements.

I would locate the element by the link text instead, example in Protractor/WebDriverJS:

element(by.linkText("Sign Out")).click();

Example in Java:

driver.findElement(By.linkText("Sign Out")).click();

First of all, copy the XPath by right-clicking the highlighted text in the pane on the right that you've shown, then selecting Copy > Copy XPath. You can then see what the XPath is by pasting it in an appropriate location (e.g. a text editor window).

  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review Commented Jul 7, 2017 at 6:02
  • 1
    @TESTasy xpath is pretty straightforward though so the recommendation made should suffice should the author choose to use xpath for his own reasons and without providing any reason why he needs a custom xpath. This doesnt even seem like a hard case, element the author asks help with has a link, has a title tag and actual text written, it should be a piece of cake to easily identify it with many different ways.Author doesnt even mention if he even bothered to try something himself, just asks for a handout, I think the above answer is more than such a question's quality merits tbh.
    – Leon
    Commented Jul 7, 2017 at 11:49
  • @TESTasy Thanks. I added one more instruction to my original answer.
    – User253489
    Commented Jul 8, 2017 at 0:57

In addition to above solution of using link text in our automation testing company, we have used xpath as below that may help you as well

1. //div//a[contains(text,'Sign Out')]

2. //div//a[text='Sign Out']

Try this one.

driver.findElement(By.linkText("Sign Out")).click();


driver.findElement(By.xpath("//a [@href = '/bgstorefront/bgb2b/em/logout' and @title = 'Sign out']")).click();

Your Answer

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

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