Xpath locators with Regular expression is not working

258 views
Skip to first unread message

Brad

unread,
May 23, 2013, 12:04:01 AM5/23/13
to seleniu...@googlegroups.com
Hi,

I tried using the Xpath locator with regular expression and it is not working and displays the following msg

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector"..

I saw a post something related to my issue as stated below. But it seems that Xpath locator with regular expression will not work properly as few browsers could not support it. But Im using FF20, IE10, Chrome latest version.

Pls find below the details of my issue

I've few similar fields that belongs to two different versions of an application.

For eg.

Uc2_centerContent1_Uc2_nameDetails1_ApplicantNameFields_day (version 1)
Uc2_centerContent1_Uc2_evoFields1_day (version 2)

Uc2_centerContent1_Uc2_nameDetails1_ApplicantNameFields_mon (version 1)
Uc2_centerContent1_Uc2_evoFields1_mon (version 2)

Uc2_centerContent1_Uc2_nameDetails1_ApplicantNameFields_year (version 1)
Uc2_centerContent1_Uc2_evoFields1_year (version 2)

And the field above is nothing but a Date of Birth fields. And eventually these have a matching pattern for each of individual fields which we can put it in the following way

Uc2_centerContent1_Uc2.*day 
Uc2_centerContent1_Uc2.*mon
Uc2_centerContent1_Uc2.*year 
 
I tried using the following method for just one field to check if it works or not. But unfortunately it is not working

new Select(SeleniumDriverClass.driver.findElement(By.xpath("//div/select[matches(@id, 'Uc2_centerContent1_Uc2.*day')]"))).selectByVisibleText("10");
new Select(SeleniumDriverClass.driver.findElement(By.xpath("//div/select[contains(@id, 'Uc2_centerContent1_Uc2.*day')]"))).selectByVisibleText("10");

Not too sure the other ways of implementing the regular expression

Can anyone suggest me to resolve this soon as i got stuck in the middle of something important.

Thanks,
Brad

Jim Evans

unread,
May 23, 2013, 5:18:12 AM5/23/13
to seleniu...@googlegroups.com
The problem is not that Selenium doesn't support regular expressions in XPath locators. The problem is that XPath itself doesn't support regular expressions. I confess I didn't thoroughly read your entire set of examples, but you'll need to explore alternative methods of element location.
Reply all
Reply to author
Forward
0 new messages