We are currently working on a selenium project. Can you guys help me to find the xpath locator for the logout button in the application?
Below is a screenshot of the code for the element for which I'm trying to find the xpath.
As @Nathan_Cooper already commented I would ask to add Ids to the objects.
If it's not possible, or if the HTML is dynamic, I would start a little higher than the other answer, in particular from
<div class="header_menu logout">
as I assume that a
div with a class
logout will always wrap the logout button.
If you want to do it manually, then you will have to trace the path from the root of the host up to where the element is being generated.
There is an easy way to get the xpath. In Mozilla FireFox install Firebug addon. Then install Firepath addon. Now visit your web page. Press F12 to open Firebug console. Click on the Firepath tab. Inspect the element you want to get the xpath of. Xpath of that element will be displayed in the Firepath console.
You can try below xpath
The above answer by QAMember should be correct. You can also try this xpath
Since the text Logout is what exactly we are looking for then no need to write text contains. You use below xpath.
According to your question you are looking for button logout, not for the text.
So as we see in the image we will find the Button is a Link control inside the Div
<div class="header_menu logout">.
the best match to locate the button is using xpath bellow.