How do find XPath when only value is given in the source code?

  • What will be the XPath of a 'Search' button from the expression mentioned above?

  • It's hard to come up with the correct XPath locator without seeing the source code of the page you're trying to automate.

    Here are few hints:

    1. If the element is a


      which looks like:

      <button class="favorite styled"

      the relevant XPath locator would be

    2. If the element is an


      with the value attribute which looks like:

      <input type="button" value="Search">

      the relevant XPath locator would be:

    3. It's also possible to use XPath Functions or Operators for example for partial match:

      //input[contains(@value, 'Search')]

    More information:

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2