0

The below code stored a list of the web element name. Is there any way to convert in string

List<WebElement>title=driver.findElements(By.xpath("//div[@class='document-card__details']//h3"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
sam
  • 57
  • 6

1 Answers1

-1

Instead of storing the WebElements you may like to store the textContent using Java8's stream() and map() you can use the following solution:

  • cssSelector:

    List<String> titles = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("div.document-card__details h3"))).stream().map(element->element.getText()).collect(Collectors.toList());
    
  • xpath:

    List<String> titles = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@class='document-card__details']//h3"))).stream().map(element->element.getText()).collect(Collectors.toList());
    

References

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352