ScrollToText not finding element

When utilizing Spy Mobile, I see the element I want to scroll to. It has text identified as ‘Enable Sensors’ in the object properties. When using ScrollToText using that same text, it fails at that step noting that it does not find the element. Is there another way to scroll down to this element or am I missing another step?

Is anyone able to help, or could this be a bug?

Hello,
May I ask which android device are you using?
In case the ScrollToText does not work, please try to use the custom keyword for scroll function.
You could get the sample custom keyword as below:

def swippingVertical(){
//Get the size of screen.
size = driver.manage().window().getSize()
System.out.println(size);

//Find swipe start and end point from screen’s with and height.
//Find starty point which is at bottom side of screen.
int starty = (int) (size.height * 0.80);
//Find endy point which is at top side of screen.
int endy = (int) (size.height * 0.20);
//Find horizontal point where you wants to swipe. It is in middle of screen width.
int startx = size.width / 2;
System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx);

//Swipe from Bottom to Top.
driver.swipe(startx, starty, startx, endy, 3000);
Thread.sleep(2000);
}

@Keyword
def boolean scrollToElement(String elementText) {
boolean isElementFound = false;
while (isElementFound == false){
ArrayList listElement = driver.findElementsByClassName(“android.widget.TextView”)
for (int i = 0; i<listElement.size(); i++){
String textItem = listElement[i].getText()
if (textItem == elementText){
isElementFound = true;
return true;
}
}
swippingVertical()
}
}

Please refer to https://www.katalon.com/resources-center/tutorials/create-custom-keyword/ for how to define and use custom keyword.

1 Like

Thank you! I will give that a try. I’m using Nexus 6 with Andriod version 7.0.