1

I want to find a specific text using regex in a xpath.

This is my xpath:

locator: //*[@class = 'android.widget.TextView' and contains(@text,'PriceBottomBarDialog-selector')]

This "PriceBottomBarDialog-selector" remains constant, the beginning text keeps changing. Can anyone please help with the regex pattern?

Thank you

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Piku
  • 21
  • 5

1 Answers1

1

You were close. You need to fix up the and you can use the Locator Strategy:

  • Xpath:

    locator: //*[@class = 'android.widget.TextView' and contains(.,'PriceBottomBarDialog-selector')]
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • It is actually the content-desc "item-Jet item-PriceBottomBarDialog-selector". Any idea how to implement this. "PriceBottomBarDialog-selector" remains constant. – Piku Aug 14 '20 at 23:35
  • @Piku If I have understtod your question properly, incase it is `content-desc="item-Jet item-PriceBottomBarDialog-selector"` you can do `contains(@content-desc,'PriceBottomBarDialog-selector')` – DebanjanB Aug 14 '20 at 23:37
  • Hi @DebsnjanB its not giving me the correct output, its giving me an error saying element not found. – Piku Aug 15 '20 at 04:35
  • @Piku This answer was to cater to your requirement of _regex pattern_. To address `element not found` can you raise a new question as per your new requirement? – DebanjanB Aug 15 '20 at 18:43