My code is working to select the N items in list view but unable to pick if scroll is there.
working code is:
int index= 1;
WebElement c = (WebElement) driver.findElements(By.className(“android.widget.TableRow”)).get(index);
if(index==0)
{
index++;
}
else
{
for (int m=1;m>=index;m++)
{
Thread.sleep(3000);
String m1 = “com.sai.android.ncertsolutions:id/r”+m ;
driver.findElement(By.id(m1)).click();
as soon as I use below code, it stop working.
int index= 1;
WebElement c = (WebElement) driver.findElements(By.className(“android.widget.TableRow”)).get(index);
if(index==0)
{
index++;
}
else
{
for (int m=1;m>=index;m++)
{
Thread.sleep(3000);
String m1 = “com.sai.android.ncertsolutions:id/r”+m ;
driver.findElement(By.id(m1)).click();
if(m>7) {
// driver.scrollTo(m1);
driver.scrollToExact(m1);
//Thread.sleep(2000);
driver.findElement(By.id(m1)).click();
}
else
{
driver.findElement(By.id(m1)).click();
Can anybody help how to write the code so that I could pick all present elements one by one (whether scroll bar is there).
Attaching image where I want to perform the action.
The below solution is specific to your app:
replace the above line with the following line:
driver.scrollTo(m+“.”);
Hopefully, it will resolve your issue ![:smile: :smile:](https://discuss.appium.io/images/emoji/twitter/smile.png?v=12)
Regards
@Abdul_Sathar_Beigh
@Abdul_Sathar_Beigh, Thanks
Its working
driver.scrollTo(m+".");
driver.findElement(By.id(m1)).click();
But every time its scrolling up and down then clicking on desired element.
2nd thing is
Seven elements are displayed in a single glance so I used loop here as
if (m>7)
{
driver.scrollTo(m+".");
driver.findElement(By.id(m1)).click();
}
else
{
driver.findElement(By.id(m1)).click();
Thread.sleep(3000);
Can we use any other alternate way instead of if (m>7)
Because some devices showing 5 elements, some showing 7 elements , some showing 11 elements in a single screen.
Its a behavior of scrollTo(), because internally it is executing two conditions in order to find the given SearchingText.
scrollTo and scrollToExact are unreliable methods
It is better to implement a generic scroll using
driver.swipe or touchActions
value of m should not be hardcoded it should be dynamic based on className
1 Like
Yes scrollTo and scrollToExact are unreliable methods
For IOS: you can use UIAUTOMATOR
For Android: webDriver.swipe(X1, y1-150, X1, y2+150, 1000);
- Swipe in a sequence(Four row will go up) and search for the element
- If its find the element then break
- If not then swipe again