Search code examples
regexseleniumxpathselenium-webdriverwatir

Can we using regular expression in xpath value?


Can we using regular expression in xpath value? I am using xpath value to identify an element on web for automation.

I have following :xpath value.

:xpath,'//*[@id="ngdialog4"]/div[2]/div[2]/table/tbody/tr/td[1]/input'

But, the last digit 4 ngdialog4 is not constant and it keeps on changing each time i open pop-up... can i use some regular expression to match any digit?


Solution

  • You could have theoretically used matches(), but it is a part of xpath 2.0, which webdriver doesn't support, see a detailed explanation here:

    Apply a starts-with() check instead:

    //*[starts-with(@id, "ngdialog")]