Hello, I am using javascript node to automate Android native app, that has webview elements on a specific page.
I have tried every solution I found to scroll to an element, but none of them works correctly.
Basically, I want to scroll on a license page to the bottom to click on an ACCEPT button, after a login operation. That ACCEPT button is disabled until the scroll to the bottom is made.
My code to scroll using TouchAction:
Note: governingBoxElement is a view that is at the bottom of the page.
page.getLicenseAgreement()
.then( licenseElement => {
return page.getGoverningLawText()
.then( governingBoxElement => {
var action = new wd.TouchAction();
action.press({el: licenseElement}).moveTo({el: governingBoxElement}).release();
return driver.performTouchAction(action);
} )
} )
This makes one scroll, but then it produces an error on Appium:
[HTTP] <-- POST /wd/hub/session/84d5ce62-178e-407d-8e4b-14b8cd8d1ab3/touch/perform 500 177 ms - 153
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1536,1952]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:29,“value”:“Coordinate [x=776.0, y=2036.0] is outside of element rect: [0,0][1536,1952]”}
Second code solution (swipe until governingLawText becomes visible):
function scroll(center){
return driver.swipe({
startX: center.x, startY: center.y,
endX: center.x, endY: 100,
duration: 0})
.then( () => {
return page.getGoverningLawText().isDisplayed()
.then( isDisplayed => {
if(!isDisplayed){
return scroll(center);
}
} )
} )
}
this.driver.getWindowSize()
.then(function(size){
var center = {
x: size.width / 2,
y: size.height / 2
};
return scroll(center, 1)
})
.catch( err => callback(Error(err)) )
.then( () => callback() )
This solution does not work because isDisplayed function returns true everytime, even when the text is not visible.
Third solution (swipe until ACCEPT button is enabled):
function scroll(center){
return driver.swipe({
startX: center.x, startY: center.y,
endX: center.x, endY: 100,
duration: 0})
.then( () => {
return page.getAcceptBtn().isEnabled()
.then( isEnabled => {
if(!isEnabled){
return scroll(center);
}
} )
} )
}
this.driver.getWindowSize()
.then(function(size){
var center = {
x: size.width / 2,
y: size.height / 2
};
return scroll(center, 1)
})
.catch( err => callback(Error(err)) )
.then( () => callback() )
Does not work either, because isEnabled() function returns false everytime, even when the button is enabled to be clicked.
I have tried also to inject Javascript on the app (driver.execute(‘mobile: scroll’, {direction: ‘down’})), but Appium returns error saying that the method has not yep been implemented.
On a last resource, I have used UIAutomator to make the scroll:
driver.elementByAndroidUIAutomator(“new UiScrollable(“new UiSelector().descriptionContains(“Governing Law:”)”).scrollIntoView(”+ pageElements.governingLawText +")").click()
this solution does not make the scroll, and clicks on the top of the page, showing the widgets of the phone.
also tried this one:
driver.elementByAndroidUIAutomator("new UiScrollable(“new UiSelector().descriptionContains(“Governing Law:”)”).scrollToEnd(50))
does not work either.
Can anyone help me to make the scroll to element work ?
Thanks.