I am trying to find out XPath for this "Sign Out" button, can anyone help me?
4 Answers
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).
-
1This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review 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.– LeonJul 7, 2017 at 11:49
-
@TESTasy Thanks. I added one more instruction to my original answer. 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();
(or)
driver.findElement(By.xpath("//a [@href = '/bgstorefront/bgb2b/em/logout' and @title = 'Sign out']")).click();
a
with thetitle
attribute but we don't usually write out the specific code for you on this site