Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in DevOps and Agile by (19.7k points)

I am trying to locate elements with generated ids wherein some part of the ID is known; for example:

id="page_x002e_x0023_default-create-firstname"

in which the last 3 words (_default-create-firstname) are known but anything preceding that is subject to change. Is this possible?

1 Answer

0 votes
by (62.9k points)

You can use the below methods:

starts-with()

ends-with()

contains()

element = driver.findElements(By.xpath("//[starts-with(@id, ‘the_text_you_want_to_match’)]");

element = driver.findElements(By.xpath("//[contains(@id, ‘the_text_you_want_to_match’)]");

element = driver.findElements(By.xpath("//*[ends-with(@id, ‘the_text_you_want_to_match’)]");

Hope this helps! 

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium certification!

Browse Categories

...