selenium - How to locate elements of table with dynamic ids using findElements? -
i have xpath dynamic ids of table. trying table ids have 'sometext' list using findelements.
issue have similar pattern except digits in id attribute vary
<tr> <td> <a id="text-132" </a> </td> <a id="text-125" </a> </td> <td> <a id="test-122"</a> </td>
i wrote following code, doesn't show error locating xpath prints nothing , list size 0
list<webelement> my_list = driver.findelements(by.xpath("//*[starts-with(@id, 'text')]")); system.out.println("size: " + my_list.size()); (int i=0; i<my_list.size(); i++) { system.out.println(my_list.get(i).gettext()); }
i prefer (probably matter of habbit) - alternative- css selectors:
selector: [attribute*=value]
example: a[href*="w3schools"]
description: selects every element href attribute value contains substring "w3schools"
in projection:
list<webelement> mylist=driver.findelements(by.cssselector("a[id*=\"text\"]")); system.out.println("size: " + mylist.size());
hope helps you.
Comments
Post a Comment