如何使用 javascript 在 android 本机应用程序中执行滚动
How to perform scroll in android native app with javascript
我正在使用 appium 和 webdriverIO 来自动化 android 本机应用程序。我需要向下滚动,我已经使用了
ele.scrollIntoView(true) //this returns not yet implemented error
还有其他向下滚动的方法吗?
您可以通过执行屏幕向上滑动操作来实现向下滚动。可以从 Boilerplate 项目中找到滑动 class 的实现。 Gestures.js class 具有所有必需的功能。这是 link 到 class
请记住,滑动是根据百分比执行的。一旦你实现了这个手势 class 你就可以像下面这样使用它:
while(!element.isDisplayed()) {
Gestures.swipeUp(0.5)
}
我没有使用 java 脚本向下滚动。但我已经用不同的方法给出了详细的答案(通过一些文本、元素和屏幕尺寸)。请看一下。
希望对您有所帮助。
我找到了一种通过直接从我的代码调用 JsonWireProtocol api 来执行向下滑动的方法。
https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
这是我的代码
module.exports.scrollAndroid = function (ele) {
console.log('driver.sessionID = ', driver.sessionId);
while (!$(ele).isDisplayed()) { . //$(ele)=$(//xpath or any other attribute)
this.scrollAPICall();
driver.pause(3000);
}
};
module.exports.scrollAPICall = function () {
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
console.log("result status >> ", this.status);
console.log("result text >> ", this.responseText);
};
url1 = `http://127.0.0.1:4723/wd/hub/session/${driver.sessionId}/touch/flick`;
xhttp.open('POST', url1);
console.log("URL >> ", url1)
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.setRequestHeader("charset", "UTF-8");
xhttp.send(JSON.stringify({
xspeed: 10,
yspeed: -100,
}));
如果你想向上滚动然后给 yspeed 作为 + 值。 ex:100
我正在使用 appium 和 webdriverIO 来自动化 android 本机应用程序。我需要向下滚动,我已经使用了
ele.scrollIntoView(true) //this returns not yet implemented error
还有其他向下滚动的方法吗?
您可以通过执行屏幕向上滑动操作来实现向下滚动。可以从 Boilerplate 项目中找到滑动 class 的实现。 Gestures.js class 具有所有必需的功能。这是 link 到 class
请记住,滑动是根据百分比执行的。一旦你实现了这个手势 class 你就可以像下面这样使用它:
while(!element.isDisplayed()) {
Gestures.swipeUp(0.5)
}
我没有使用 java 脚本向下滚动。但我已经用不同的方法给出了详细的答案(通过一些文本、元素和屏幕尺寸)。请看一下。
希望对您有所帮助。
我找到了一种通过直接从我的代码调用 JsonWireProtocol api 来执行向下滑动的方法。 https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
这是我的代码
module.exports.scrollAndroid = function (ele) {
console.log('driver.sessionID = ', driver.sessionId);
while (!$(ele).isDisplayed()) { . //$(ele)=$(//xpath or any other attribute)
this.scrollAPICall();
driver.pause(3000);
}
};
module.exports.scrollAPICall = function () {
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
console.log("result status >> ", this.status);
console.log("result text >> ", this.responseText);
};
url1 = `http://127.0.0.1:4723/wd/hub/session/${driver.sessionId}/touch/flick`;
xhttp.open('POST', url1);
console.log("URL >> ", url1)
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.setRequestHeader("charset", "UTF-8");
xhttp.send(JSON.stringify({
xspeed: 10,
yspeed: -100,
}));
如果你想向上滚动然后给 yspeed 作为 + 值。 ex:100