Model Page我正在尝试滚动到屏幕中的特定元素,收到以下错误:
Eclipse错误日志:
org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource. (Original error: That device doesn't know how to respond to 'mobile: 'scroll--it's probably not using Appium's API) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
以下是Appium错误日志:
> info: <-- POST /wd/hub/session/0b79ffed-89dc-66ca-27b0- cf6ef260181a/element 200 18.561 ms - 122
> info: --> POST /wd/hub/session/0b79ffed-89dc-66ca-27b0- cf6ef260181a/execute {"script":"mobile: scroll","args": [{"direction":"down","element":"c845c15a-918c-019f-67a0-ae6a1dbe34c5"}]}
> info: [debug] Responding to client with error: {"status":9,"value": {"message":"The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource. (Original error: That device doesn't know how to respond to 'mobile: 'scroll--it's probably not using Appium's API)","origValue":"That device doesn't know how to respond to 'mobile: 'scroll--it's probably not using Appium's API"},"sessionId":"0b79ffed-89dc-66ca-27b0-cf6ef260181a"}
> info: <-- POST /wd/hub/session/0b79ffed-89dc-66ca-27b0-cf6ef260181a/execute 500 3.576 ms - 449
> info: --> DELETE /wd/hub/session/0b79ffed-89dc-66ca-27b0-cf6ef260181a {}
> info: Shutting down appium session
> info: [debug] Stopping selendroid server
> info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/0b79ffed-89dc-66ca-27b0-cf6ef260181a","method":"DELETE"}
> info: [debug] executing cmd: C:\Users\GangaiahL\AppData\Local\Android\sdk\platform-tools\adb.exe -s 00bd9781 shell "am force-stop au.com.carsguide"
> info: [debug] [SELENDROID] getSystemUiVisibility() after setting = 0
> info: [debug] [SELENDROID] getSystemUiVisibility() after setting = 0
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] Cleaning up appium session
> info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"0b79ffed-89dc-66ca-27b0-cf6ef260181a"}
> info: <-- DELETE /wd/hub/session/0b79ffed-89dc-66ca-27b0-cf6ef260181a 200 1526.913 ms - 76 {"status":0,"value":null,"sessionId":"0b79ffed-89dc-66ca- 27b0-cf6ef260181a"}
以下是我的代码: 并抛出错误行-js.executeScript(&#34; mobile:scroll&#34;,scrollObject);
@Test
public void test() throws InterruptedException
{
System.out.println("TEST STARTED");
driver.findElement(By.linkText("All Makes")).click();
Thread.sleep(10000);
//driver.findElement(By.linkText("AUDI")).click();
WebElement element = driver.findElement(By.linkText("AUDI"));
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
scrollObject.put("element", ((RemoteWebElement) element).getId());
js.executeScript("mobile: scroll", scrollObject);
答案 0 :(得分:0)
我相信很多滚动功能已被删除。这包括常见的scrollTo()
方法。如果您希望能够滚动,则需要使用driver.swipe(int startx, endx, starty, endy, duration)
命令。
如果你使用它,你可以用这个方法构建一些好的滚动方法;元素位置,大小和屏幕大小。 (注意由于某种原因,Android和iOS之间的回报不同)
答案 1 :(得分:0)
1.屏幕上有可滚动的视图吗? 2.如果您在屏幕中有可滚动视图,请在视图上滚动而不是在文本上滚动。
OR
试试这个并问:
String name ="AUDI";
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+name+"\").instance(0))");
OR
MobileElement element = (MobileElement) driver.findElementByClassName("android.widget.ListView");
JavascriptExecutor js = (JavascriptExecutor)driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
scrollObject.put("element", ((RemoteWebElement) element).getId());
scrollObject.put("text", "AUDI");
js.executeScript("mobile: scrollTo", scrollObject);
尝试这个。
我已经解决了你的问题,我制作了对每个人都有帮助的视频。
请在此链接中找到您的问题的解决方案:https://www.youtube.com/watch?v=EdgStq4d0bQ。
更新的答案:
我已将我的appium更新为1.5.3并修复了您的问题&amp;它对未来也有帮助。 请参阅此视频:https://www.youtube.com/watch?v=bT3tqaLNn-Y
答案 2 :(得分:0)
使用以下代码,它应该有效:
用于向上滑动:
driver.swipe(350,800,350,350,2000);
向下滑动
driver.swipe(350,350,350,800,2000);