Quality Testing

Quality is delighting customers

When elements extracted using dynamic xpath I got all similar type of elements in list. But now I want click on particular X element. How should I achieve this?
List list = driver.findElements(By.xpath("//*[starts-with(@id,'yui-')]/a"));
Here I got list of elements which start from yui, now I want to click on elements yui-120, how should I achieve this?

Views: 375

Reply to This

Replies to This Discussion


N should be replaced with actual index number.

u must go for findElements(By.list)...

Many web sites create dynamic element on their web pages where Ids of the elements gets generated dynamically. Each time id gets generated differently. So to handle this situation we use some JavaScript functions. starts-with if your dynamic element's ids have the format where button id="continue-12345" where 12345 is a dynamic number you could use the following
XPath: //button[starts-with(@id, 'continue-')]
Sometimes an element gets identfied by a value that could be surrounded by other text, then contains function can be used.
To demonstrate, the element
can be located based on the ‘suggest’ class without having to couple it with the ‘top’ and ‘business’ classes using the following
XPath: //input[contains(@class, 'suggest')].


TTWT Magazine





© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service