我想问一下我们什么时候在Appium中使用触摸动作。我还想问:我们是否可以使用触摸操作来点击/按下android.widget.EditText元素并对其执行sendKeys操作。我可以有一个可行的例子来测试它吗?
发布于 2017-02-17 06:07:28
每当我们想要在设备上的特定元素上点击/轻敲时,我们都会使用触摸操作。
用于单击的
您可以对EditText元素使用触摸操作,如bewlow:
driver.findElement(By.xpath("your element xpath/id")).click();
用于键入的
此外,您还可以为EditText元素使用sendKeys,如下所示:此内部单击元素,清除文本并键入您要发送的字符串。
driver.findElement(By.xpath("your element xpath/id")).sendKeys("textToBeTyped");
或
您可以单独单击并发送关键字,而无需清除文本元素中的现有文本,如下所示:
driver.findElement(By.xpath("your element xpath/id")).click();
driver.getKeyboard().sendKeys(textToBeTyped);
发布于 2017-02-21 08:54:30
1.public void tap(int fingers, int x, int y, int duration) {
appiumDriver.tap(fingers, x, y, duration);
}
2. public void swipe(int startx, int starty, int endx,int endy,int duration)
{
TouchAction touchAction = new TouchAction(appiumDriver);
System.out.println(startx+" "+starty);
System.out.println("Entering swipe");
System.out.println("Swipe from "+startx +" " +starty +"to" +endx +" " +endy );
touchAction.press(startx, starty).waitAction(duration).moveTo(endx,endy).release().perform();
}
3. public void longClick(String element, int index, int clickCount, int X, int Y) {
WebElement webElement = appiumDriver.findElement(By.xpath(element));
TouchAction Action = new TouchAction(appiumDriver);
Action.longPress(webElement).release().perform();
}
4. public void drag( String element, int index, int xOffset, int yOffset) {
WebElement webElement = appiumDriver.findElement(By.xpath(element));
TouchAction drag=new TouchAction(appiumDriver);
int startX=webElement.getLocation().getX();
int startY=webElement.getLocation().getY();
System.out.println("startX: "+startX+" startY: "+startY);
drag.press(startX,startY).moveTo(xOffset,yOffset).release().perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
发布于 2018-11-28 10:26:30
在所有appium客户端库中,都创建了触摸对象,并为其提供了一系列事件。首先,您必须使用then驱动程序初始化TouchAction对象,然后链接您的步骤才能执行操作。您可以演示各种手势,例如:
您可以使用给定的参数来完成此操作,例如每个操作的持续时间、等待设置、设置释放等。
示例:
为了按下带有坐标的元素:
new TouchAction(driverObject).tap(PointOption.point(x,y)).perform();
或者:
new TouchAction(driverObject).press(PointOption.point(x,y)).perform();
为了以毫秒的Z持续时间将元素从pointA滑动到pointB
//wait parameters for duration purposes
WaitOptions waitOptions = new WaitOptions();
waitOptions.withDuration(Duration.ofMillis(millis));
//The action
new TouchAction(driverObject).longPress.press(fromPoint)
.waitAction(waitOptions).moveTo(toPoint).release().perform();
https://stackoverflow.com/questions/42288409
复制相似问题