0 votes
1 view
in Devops and Agile by (19.8k 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 (63.4k 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! 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...