I have a table where each row will have a download link with a (partly) auto-generated id element. The reason for this is that the actual href-element will allways be \"#\",
To print the List of id attribute of the element you need to induce WebDriverWait for the visibilityOfAllElementsLocatedBy()
and you can use Java8 stream() and map() and you can use either of the following Locator Strategies:
cssSelector
:
List myID = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("td.journalTable-journalPost>a.htext-small"))).stream().map(element->element.getAttribute("id")).collect(Collectors.toList());
System.out.println(myIDs);
xpath
:
List myIDs = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//td[@class='journalTable-journalPost']/a[@class='htext-small' and text()='Download']"))).stream().map(element->element.getAttribute("id")).collect(Collectors.toList());
System.out.println(myIDs);