I have a list of contacts and have to choose multi contacts by search.
Can any one please tell me how to select contact by name or other reliable way
Hi Pushpank,
for Lists, we need to handle in different way.
1.first get the all items in the list i.e.driver.findelements(By.xpath(//android.widget.Listview/android.widget.relativeLayout))
2.lterate the loop with you matching element(name)
3.Click on name if it is matched.
4.if your search element is not found in the displayed list,swipe the list and again get the list of items and verify it.
Hello Gnanehwar,
Thank you very much for reply.
As you guide i am using below code but its not working for me, can you guide me again in it or pls share a sample code for multi item select in the list.
List allElements = driver.findElementsByClassName(“android.widget.RelativeLayout”);
java.util.Iterator i = allElements.iterator();
while(i.hasNext()) {
WebElement row = i.next();
System.out.println(row.getText());
}
Hi Pushpank,
please find the below piece of code which can help you to work with lists.
boolean bFlag = true;
while(bFlag){
List posts = getDriver().findElements(By.xpath("//android.widget.ListView/android.widget.RelativeLayout"));
if(posts.size()!=0){
for(int iCounter=0;iCounter<posts.size();iCounter++){
//Compare the with actual and expected contact names,Click on if its found in the list
if(posts.get(iCounter).findElement(By.id(“conatctid”))).getText().equals(“expected value”)){
posts.get(iCounter).findElement(By.id(“conatctid”))).click();
bFlag = false;
break;
}
}else{
getRep().report(“Verify contacts available for user”, 1, “Contacts not available for user”, 0);
}
if(bFlag){
SwipeUp(0.60, 0.40, “Posts”);
}
}
–Depends on requirement you can implement or change the code.