RE: How to use Regular expression to find a web element.

I want to fetch out the text of all the elements whose id start with “WebPart_twp”

The Complete xpath is given Below:

I have Tried this with below Example but unfortunately it doesn’t work

Error Message:
Unable to locate element: {“method”:”xpath”,”selector”:”.//*[@id=’WebPart_twp([0-9]+)’]/tbody/tr/td/div”

Please do some needful.

Vandana Maurya

Vandana_Maurya Default Asked on December 15, 2014 in Selenium WebDriver.
Add Comment
1 Answers
Best answer

Hi Vandana,

Try this :

List <WebElement> elementList = driver.findElements(By.xpath(".//*[contains(@id,"WebPart_twp")]"));

Lakshay Sharma

Professor Answered on December 15, 2014.

and to get Text  use
For(WebElment text: elementList)
String ElmentText=text.getText():


on December 15, 2014.

Thank You so much Lakshay  and Ankit 🙂

on December 16, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.