How to list all the elements in a list in Appium

syed naveed :

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.

Sameer Arora :

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());
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=206358&siteId=1