问题描述: 在iOS Chrome应用中,使用Appium进行触摸操作时,"Press"和"Move To"方法无法正常工作。
解决方法: 一种解决方法是使用Appium的TouchAction类的"longPress"和"moveTo"方法来执行触摸操作。
以下是一个使用TouchAction类的示例代码:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.LongPressOptions;
import io.appium.java_client.touch.offset.ElementOption;
import org.openqa.selenium.WebElement;
public class TouchActionExample {
private AppiumDriver driver;
public TouchActionExample(AppiumDriver driver) {
this.driver = driver;
}
public void performTouchAction() {
WebElement element = driver.findElementByXPath("//some-xpath");
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(LongPressOptions.longPressOptions()
.withElement(ElementOption.element(element)))
.moveTo(ElementOption.element(element))
.release()
.perform();
}
}
在上述示例代码中,通过使用TouchAction类的"longPress"和"moveTo"方法,可以模拟"Press"和"Move To"操作。"longPress"方法接受一个LongPressOptions对象,其中指定了要长按的元素。"moveTo"方法接受一个ElementOption对象,其中指定了要移动到的元素。
请根据自己的实际情况修改示例代码中的元素定位方式和要执行的操作。
希望以上解决方案能对您有所帮助。