How do I select this checkbox in the listView?


#1

Hello,

How can I select the Primary Account checkbox? in the ListView?
I am trying this

		    List<AndroidElement> list = driver.findElements(By.id("com.ezepay:id/rvBankList"));
				    list.get(1).click();

I am unable to click on that particular element, could you please help?
I am new to Appium


#2

Try this and let me know if this works

try this driver.findElementByAndroidUIAutomator(“new UiSelector().className(“android.widget.Button”).text(“Primary Account”)”);


#3

No luck.
It didn’t work for me @Aish.appium ;(

Can you please suggest if there are any better approach?


#4

Try this List list = driver.findElements(By.id(“com.ezepay:id/bMakePrimary”));
list.get(0).click();
or this
driver.findElement(By.xpath("//*[@resource-id=‘com.ezepay:id/bMakePrimary’]")).click();


#5

List list = driver.findElements(By.id(“com.ezepay:id/bMakePrimary”));
list.get(0).click();
For this I am not getting an element click(); I can’t type that in the Eclipse, I think it is because we have used Element"s" .click is underlined. Syntax Error maybe

driver.findElement(By.xpath("//*[@resource-id=‘com.ezepay:id/bMakePrimary’]")).click();
For this I am getting this: A location path was expected, but the following token was encountered: ‘com.ezepay

Not sure what is wrong.


#6

try
Try this List list = driver.findElement(By.id(“com.ezepay:id/bMakePrimary”));
list.get(0).click();

dont put findElement’s’


#7

If I don’t put Element’s’, I don’t get the option for (.get(0)) index.
Tried all the ways to get this right, but no luck.

Can anyone help me with this please?


#8

I am sorry, i dont have any such application where i use this so cant try and confirm if this should work but option one where you are getting error on click() method , try below code and see if this takes care of the error or solves the issue.

List list = driver.findElements(By.id(""));
list.get(0).click();


#9

Hey thanks.

I used this

List list = driver.findElements(By.id(“com.ezepay:id/bMakePrimary”));
((WebElement) list.get(1)).click();

Appium gives success message 200.

But, Java is giving me this, without any actions on the screen
Index: 1, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at ezebase.testSelectingPrimaryAccount(ezebase.java:232)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:580)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


#10

If you can try this once and let me know if this solves.

List list = driver.findElements(By.id(“com.ezepay:id/bMakePrimary”));
list.get(0).click();


#11

Thank you.

If I use only the above click(); gives error in Java Eclipse

So I used this
List list = driver.findElements(By.id(“com.ezepay:id/bMakePrimary”));
((WebElement) list.get(0)).click();

I get this error

Index: 1, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at ezebase.testSelectingPrimaryAccount(ezebase.java:232)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:580)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


#12

Hello @Aish.appium
No luck yet, it is not working, I tried in all possible ways. I am unable to locate the locator.
I used the tap gesture, it is working fine for now.
But, it is a bad approach. Unsure, how to do this.

Did anyone else face this issue earlier? were you able to acheive the results?


#13

what if you use MobileElement instead of WebElement?

List list = driver.findElements(By.id(“com.ezepay:id/bMakePrimary”));
((MobileElement) list.get(0)).click();
Try to see first how many element are found in your list.
Systemout.println(list.getSize());

When I have more elements with the same ID i’m using this approach, with page objects and works as expected

@AndroidFindBy(id = “base_hint_title”)
public List list;

list.get(1).click();