!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: How to use a regular expression in XPath locator  (Read 5086 times)

Offline divya.madaan

  • Selenium User
  • *
  • Posts: 12
How to use a regular expression in XPath locator
« on: September 12, 2012, 01:44:16 AM »
Hi,

I want to use regular expression in XPath locator "//div[@id='bommaa10filters']/label/div/ul/li/div[2]"

In above XPath "bommaa" is variable, so I want Webdriver to recognize every element that contains "10filters']/label/div/ul/li/div[2]"

I have tried "//div[matches(@id,'*10filters')]/label/div/ul/li/div[2]" but it doesnot work and an error comes "The given selector //div[matches(@id,'*10filters')]/label/div/ul/li/div[2] is either invalid or does not result in a WebElement."

Can anybody help me with this please?

Offline Selenium Webdriver Admin

  • Administrator
  • Full Member
  • *****
  • Posts: 235
Re: How to use a regular expression in XPath locator
« Reply #1 on: September 12, 2012, 02:36:22 AM »
Use this xpath - //div[contains(@id,'10filters')]/label/div/ul/li/div[2]

Offline divya.madaan

  • Selenium User
  • *
  • Posts: 12
Re: How to use a regular expression in XPath locator
« Reply #2 on: September 12, 2012, 02:47:16 AM »
Thanks...it worked.

Selenium Webdriver

Re: How to use a regular expression in XPath locator
« Reply #2 on: September 12, 2012, 02:47:16 AM »

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
3041 Views
Last post March 28, 2012, 06:58:25 PM
by Simon Stewart
1 Replies
1346 Views
Last post April 01, 2012, 06:52:10 PM
by Oliver
10 Replies
1317 Views
Last post April 15, 2012, 05:33:03 PM
by Ross Patterson
1 Replies
692 Views
Last post July 25, 2012, 03:39:11 PM
by dlai
1 Replies
1780 Views
Last post October 11, 2012, 11:50:33 PM
by shivas.cit
1 Replies
743 Views
Last post February 28, 2013, 07:15:35 AM
by Andrew_
3 Replies
1952 Views
Last post March 23, 2013, 09:37:00 AM
by rnaren27