Can we using regular expression in xpath value? Can we using regular expression in xpath value? selenium selenium

Can we using regular expression in xpath value?


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")]


Using XPath 2.0 :

:xpath,'//*[matches(@id, '^(ngdialog)[0-9]')]/div[2]/div[2]/table/tbody/tr/td[1]/input'


Since you are using Watir, you could also use a regular expression to find the ngdialog element. XPath could then be used for the other portion of the path (note the starting of the XPath with ./ is used to tell Watir to look within the ngdialog):

browser.element(:id => /ngdialog/).checkbox(:xpath => './div[2]/div[2]/table/tbody/tr/td[1]/input')