我正在使用Java和Appium 1.2.0自动化原生Android应用。我想自动长按列表中的一行以显示一些可通过长按访问的选项,现在我手动测试它。这就是我的尝试:
WebDriverWait wait = new WebDriverWait(driver, 30);
HashMap<String,String> longtapObj= new HashMap<String,String>();
WebElement elem = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.ListView[1]/android.widget.RelativeLayout[1]")));
JavascriptExecutor js = (JavascriptExecutor) driver;
longtapObj.put("element", ( (RemoteWebElement) elem).getId() );
js.executeScript("mobile:longClick", longtapObj);
Appium服务器日志错误:
2014-09-02T23:29:45.808Z - debug:收到params的请求:{“args”:[{“element”:“5”}],“script”:“mobile:longClick”} 2014-09-02T23:29:45.810Z - debug:响应客户端没有实现方法
2014-09-02T23:29:45.810Z - info:&lt; - POST / wd / hub / session / f66d9550-c47e-4380-a0f4-c819a12f59a9 / execute 501 3.656 ms - 158
2014-09-02T23:29:48.518Z - info: - &gt; GET / wd / hub / status {}
Eclipse JUnit错误:
org.openqa.selenium.WebDriverException:尚未实现。请帮助我们:http://appium.io/get-involved.html(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:9毫秒
如果注释掉js.executeScript语句(“mobile:longClick”,longtapObj);没有错误被抛出。感谢是否有人知道在本机Android应用程序中使用Appium实现日志记录的正确方法。
答案 0 :(得分:5)
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> longTapObject = new HashMap<String, String>();
longTapObject.put("element",((RemoteWebElement)w1).getId());
js.executeScript("mobile: longClick", longTapObject);
以上代码在java中为我工作 Appium版本1.2.4.1
答案 1 :(得分:2)
版本1.5的变更
删除久消不久的移动设备:xxx
所以你应该:
安装Android支持存储库...
Android测试支持库可通过Android SDK Manager
获得
通过SDK Manager下载Android支持存储库:
使用TouchAction
driver.performTouchAction(new TouchAction(driver).tap(x,y));
答案 2 :(得分:1)
mobile:longClick is no longer supported by appium version greater than 1.0.0. As you are using Appium version 1.2.0. so you have to perform this action by using something like this.
例如:
testObject = this.WaitAndGetElement();//element on which long tap is to be performed
TouchAction action = new TouchAction(rm);// rm is the instance of appium driver.
Thread.Sleep(1000);
action.Press(testObject).Wait(1000).Perform();
有关详细信息,请访问:TouchAction
如果有帮助请告诉我
答案 3 :(得分:0)
public void longClick(String element) {
// TODO Auto-generated method stub
WebElement webElement = appiumDriver.findElement(By.xpath(element));
TouchAction Action = new TouchAction(appiumDriver);
Action.longPress(webElement).release().perform();
}