How to extract the dynamic values of the id attributes of the table elements using Selenium and Java

Until you find the element first, you can’t retrieve the attribute values of it.

Use findElements method to fetch all links using the following locator

table tr td[class="journalTable-journalPost"] a

Then iterate through each element using for-each to fetch id for each element.

Sample code:

List<WebElement> listOfLinks = driver.findElements(By.cssSelector("table tr td[class="journalTable-journalPost"] a"));

for(WebElement link: listOfLinks) {
     System.out.println("id:" + link.getAttribute("id"));
}

Leave a Comment