New answers tagged xpath
Since the text Logout is what exactly we are looking for then no need to write text contains. You use below xpath. (By.xpath("//div[.='Logout']"));
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. OR 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 ...
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. //div[contains(@class ...
The above answer by QAMember should be correct. You can also try this xpath //div[contains(text(),'Logout')]
You can try below xpath //*[@class='item']/div[text(),'Logout']
Julian brought up good points, i.e. make sure your element is unique and does not change. If it is not, then make sure you talk to your developer to add an attribute that is unique and unchanging. You can do driver.findElement(By.cssSelector("li input[class='edit']"));
Normally when I have trouble to find an element, I open the selenium IDE and click on this element and then see what the identifier that it captures
Top 50 recent answers are included