Search code examples
typescriptwebdriver-ioui-testing

How to find an element on a page with WebDriver.io that doesn't have an identifier


I want to find and run a test on this element: enter image description here

It has a bunch of classes but those classes are used by other elements as well. How can I find this element on webdriver.io using Typescript?


Solution

  • You have a few options to achieve that:

    1. Find by partial text

      To find a anchor element whose visible text partially matches your search value, query it by using *= in front of the query string

      For instance:

      $('*=Total')
      
    2. Find by certain text:

      The same technique can be applied to elements as well.

      For instance:

      $('span=Total: 137216');
      
    3. Find by xPath

      To query elements via a specific xPath

      $('//body/div[1]/div[1]/main[1]/div[3]/div[1]/div[3]/span[1]')