Please help me on this am trying to locate the element using xpath

enter image description here



Maybe it works. Try to find unique attribute.

  • Its not working, i have two buttons with same name as "login-btn2" – Kirankumar C R Jun 28 '19 at 13:52
  • 1
    You can find all .login-btn2 with findElements (or equivalent on your Selenium implementation) and filter out the list however you want (by index or condition) – João Farias Jun 28 '19 at 14:22

Here's one way to locate the Xpath or CSS Selector for a given web element:

  • Using Chrome, open Developer Tools. You can also right-click on web element and select "Inspect"
  • Select Elements tab
  • Locate web element using right-click, Inspect or use the arrow icon near the Element tabs to select the web element. Either way, the web element will be highlighted in the Elements pane.
  • With the element highlighted in Elements pane, right click on it and go to "Copy > Copy Xpath". Alternatively, you can select "Copy > Copy Selector". This will copy the correct Xpath or CSS Selector to your clipboard.

Note: Keep in mind, Xpath is slow and a brittle way of locating elements in Selenium as it is dependent on an exact path in the DOM. If the UI changes, the Xpath will most likely break. You'll spend a lot more time in maintenance fixing your Xpaths. Instead, use CSS Selectors, IDs, Names for faster element location. These are also more direct way of finding the correct element in Selenium and is less likely to fail when the app/UI changes.


Usually the simplest solution will work. Look for the first button whose text is "Client Login":

//button[.='Client Login']

If that doesn't work then there's either more than one match, or the element exists inside an iframe.

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