0

I have some text like this: "Viewing 101-200 of 244". I would like to find this with an xpath.

Right now I use this:

//*[contains(text(),'Viewing') and contains(text(),'of')] which is all very well and good but could potentially match other patterns. What I would like to do is something like in a regular expression as in the following:

//*[contains(text(),'Viewing [0-9]+ of [0-9]+')]

But I can't figure out how to use wild cards as above. Is there any way to do this? My guess is no?

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
Tony
  • 367
  • 1
  • 7
  • 17
  • 1
    what version of XPath does your tooling support? – JimmyJames Jan 05 '16 at 19:28
  • A common way of avoiding this is to get the text from the element via normal xpath and let the calling application / test worry about patterns. Maybe this is in the header of a results table, so you might use (in java/c#-like pseudo code) `var results[] = GetTextFromElements(GetElementsByXpath("//table/thead/tr/td"));` then do your pattern matching where it's easier and more understandable. – Paul Hicks Jan 05 '16 at 19:36
  • Since we started using Web Center, the id's are long, crazy random names so I cannot really use: //*[@id="pt1:r1:0:grppcr6:0:pt2:j_id__ctru5pc8"]/div – Tony Jan 05 '16 at 20:08
  • How do I verify my xpath version? – Tony Jan 05 '16 at 20:31
  • Doesn't have to be an id. Relative locators can be useful. Like `//table[1]/thead/tr/td[2]`. – Paul Hicks Jan 05 '16 at 20:43

0 Answers0