我有一个测试 IOS 应用程序的场景,如下所示:
- 长按某个元素。
- 将该元素移动到所需位置。
我正在使用以下代码:
TouchAction action = new TouchAction(driver)
action.long_press(element1).move_to(element2).wait(500).release().perform()
但它不适合我。需要什么好的建议吗
我也为此遇到了麻烦。但我解决了这个问题,如下所示:
TouchAction action = new TouchAction(driver);
action.longPress(elem1).waitAction(3000).moveTo(elem2).perform().release();
waitAction
将等待完成 longPress
操作,然后执行 moveTo
操作。
我发现 longPress() 组合都不起作用,所以我得到了这个变体,你可以强制它执行按下然后移动。在 Android 和 iOS 上测试过,似乎不适用于 UWP
new TouchAction(driver)
.press(PointOption.point(256, 1115))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
.perform()
.moveTo(PointOption.point(256, 600))
.release()
.perform();
//You need to import following
import org.openqa.selenium.WebElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.LongPressOptions;
import io.appium.java_client.touch.offset.ElementOption;
//first for the intial location to be long pressed
WebElement first= driver.findElementByXPath("//*[@content-desc='15']");
//second location on which you need to move to
WebElement second= driver.findElementByXPath("//*[@content-desc='45']");
TouchAction action = new TouchAction(driver);
//performing the long press
action.longPress(new LongPressOptions().withElement(new
ElementOption().withElement(first))).perform();
//performing the move to touch operation
action.moveTo(new ElementOption().withElement(second)).perform();
如果你已经有了元素的引用那么你会这样做:
TouchAction action = new TouchAction(driver);
action.longPress(new ElementOption().withElement(first))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(3000)))
.moveTo(new ElementOption().withElement(last))
.release()
.perform();
以下解决方案适用于我的 iOS with python:
TouchAction(context.driver).long_press(source_element).move_to(destination_element).release().perform()
这对我有用(在Android上尝试过)
动作 actions = new Actions(driver); actions.clickAndHold(element1).pause(2000).moveToElement(element2).perform();
action.press(Element1).moveTo(Element2).release().perform();