0

I have an xml as below <div class="_4079e399">The age is 24 years</div> From here using only xpath expression I have to extract the number 24. I tried //*[@class="_4079e399"]/translate(., translate(.,'0123456789',''), '') in https://www.freeformatter.com/xpath-tester.html website and it's extracting the correct value there. But as soon as I put it in chrome in console it doesn't detects any element. Please if someone can help me construct an xpath expression for this so that it's recognizable and works.

  • 2
    In selenium, xpaths are used for element identification and not used for extracting/getting data.. Is this a selenium question? - if so, you'll need to use `yourelement.text` to get the value then manipulate the string, and you'll need to share your code if you need help with it ... But, if it's not selenium, consider removing the tag to reduce confusion? :-) – RichEdwards Aug 27 '20 at 15:14

1 Answers1

0

Per the Freeformatter.com XPath Tester / Evaluator,

It fully supports XPath 2.0 / 3.0 specification.

and, in fact, a function call as the last step of the XPath requires XPath 2.0.

The problem is that Chrome only supports XPath 1.0.

If you can be sure that there is only a single targeted element, you can rearrange your XPath 2.0 expression to be compatible with XPath 1.0:

translate(//*[@class="_4079e399"], 
          translate(//*[@class="_4079e399"],"0123456789",""), 
          "")

If multiple elements may match, you'll have to process them individually in the language hosting the XPath call.

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240