syed naveed
syed naveed

Reputation: 95

How to list all the elements in a list in Appium

I am looking for Appium code where it will list all the web elements present in a class, For instance i want to try something as

List<WebElement> listOfElements;
listOfElements = (WebElement) driver.findElements(By.xpath("//*[contains(@class,'view.test')]"));

System.out.println(listOfElements);

The class contains at least 8 elements. Is there a way to list all the 8 elements in appium

The above code is not working , I don't see any appium library for importing list too. So, is there a way to get entire list of identifiers belonging to a class in appium.

Upvotes: 0

Views: 2997

Answers (1)

Sameer Arora
Sameer Arora

Reputation: 4507

You can fetch the elements in a list and then iterate through that list to print the elements.
You can do it like:

List<WebElement> listOfElements = driver.findElements(By.xpath("//*[contains(@class,'view.test')]"));
for(WebElement element: listOfElements){
    System.out.println(element);
}

And if you want to print the element text(if it is present), then you can do it like:

List<WebElement> listOfElements = Constant.driver.findElements(By.xpath("//*[contains(@class,'view.test')]"));
for(WebElement element: listOfElements){
    System.out.println(element.getText());
}

Upvotes: 2

Related Questions