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

      <button>
      

      which looks like:

      <button class="favorite styled"
              type="button">
          Search
      </button>
      

      the relevant XPath locator would be

      //button[text()='Search']
      
    2. If the element is an

      <input>
      

      with the value attribute which looks like:

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

      the relevant XPath locator would be:

      //input[@value='Search']
      
    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