-2

My Text in UI is "Resend in 48 sec" in which "48" is a timer which is dynamic so I want to crate an Xpath using the contains and Inside Contains I am using Regex but still unable to find the Element

//*[contains(@content-desc,"Resend in .*?[0-9a-zA-Z]*[0-9][0-9a-zA-Z].* sec")]

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
RAJA RAM
  • 109
  • 8

3 Answers3

1

Selenium is still using XPath 1.0, which was defined over 20 years ago and has no support for regular expressions.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

You can use this XPath instead:

//*[contains(@content-desc,"Resend in") and(contains(@content-desc,"sec"))]

Now you can get this element, get it's content-desc attribute value and then validate the content of that attribute

Prophet
  • 32,350
  • 22
  • 54
  • 79
0

You may wanna do this instead :

String regEx = ".*?[0-9a-zA-Z]*[0-9][0-9a-zA-Z].*";
driver.findElement(By.xpath("//*[contains(@content-desc,'Resend in') + '"+regEx+"'  + and(contains(@content-desc, 'sec')) ]"));
cruisepandey
  • 28,520
  • 6
  • 20
  • 38