Using selenium java i want to get all the values of a specified attribute within the current page exemple :
<div my_attribute="value1">
<div my_attribute="value2">
<div my_attribute="value3">
how i get the result : value1, value2, value3 to store them in a list of strings
CodePudding user response:
You can get a list of web elements with attribute my_attribute
and then iterate over that list to collect all the attribute values.
Something like this:
List<WebElement> list = driver.findElements(By.xpath("//div[@my_attribute]"));
List<String> values = new ArrayList<>();
for(WebElement el:list){
String value = el.getAttribute("my_attribute");
values.add(value);
}