1

I have list of items that has a check option, I need to select all the items. The attributes available are resource-id, index which are static. Instance which is dynamic and increases with the list of items eg: 0,1,2...

How can I select all the checkboxes in the list.

WebElement checkboxSelection = driver.findElementByXPath("//android.widget.xxxxx[contains (@instance, '0')]");
        checkboxSelection.click();

WebElement checkboxSelection = driver.findElementByXPath("//android.widget.xxxxx[contains (@instance, '1')]");
        checkboxSelection.click();

WebElement checkboxSelection = driver.findElementByXPath("//android.widget.xxxxx[contains (@instance, '2')]");
        checkboxSelection.click();

The above code does just a single selection, since I want to select also 1,2,...n how could I achieve this?

I tried something like this and this doesn't result in locating the element

for (int j=0;j<=10;j++){
            WebElement contactSelection = driver.findElementByXPath("//android.widget.CheckBox"+j+"instance");
            contactSelection.click();
        }
  • Doesn't Appium support findElementsByXpath method? – Alexey R. Aug 7 '18 at 11:32
  • What do you mean ? I'm using Xpath, please have a look at the code – WiredTheories Aug 7 '18 at 11:48
  • What are the possible values for instance attribute? – Alexey R. Aug 7 '18 at 11:51
  • 0,1,2 ..... like already mentioned in the post – WiredTheories Aug 7 '18 at 11:54
2

Try this code:

List<WebElement> elements = driver.findElements(By.xpath("//android.widget.xxxxx"));
for(WebElement element: elements){
    element.click();
}

first line will return you all the available elements which you then click one-by-one.

| improve this answer | |
  • R Perfect, this works for the first view, what if I have to scroll and select the next items ? Thanks – WiredTheories Aug 7 '18 at 12:52
  • Then you perform the same code (after scrolling). – Bill Hileman Aug 7 '18 at 13:19
  • I'm facing issues when I try to do scroll with Touchactions – WiredTheories Aug 7 '18 at 14:04
  • I think it is worth raising a separate question for that. – Alexey R. Aug 7 '18 at 14:54
  • @WiredTheories oh, I can see that you have already raised it :) Sorry! – Alexey R. Aug 7 '18 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.