在 Appium 中长按 AndroidElement
Long press on AndroidElement in Appium
我正在尝试对 Appium 中的 AndroidElement 执行长按操作。我发现我需要对此元素执行 TouchAction,但是......它只接受 WebDriver 作为参数,而不是我正在使用的 AndroidDriver。因此它不会工作。
TouchAction action = new TouchAction(AndroidDriver);
action.longPress(element, 10000);
我一直在寻找一些答案。 LongPress(或类似的东西)用于我现在正在写的最后一个测试。
解决方法是使用 io.appium.java_client.MultiTouchAction
。
MultiTouchAction multiTouch = new MultiTouchAction(AndroidDriver);
multiTouch.add(createTap(element, duration));
multiTouch.perform();
试试这个。
TouchAction action = new TouchAction();
action.longPress(webElement).release().perform();
下面的代码将在 android 应用程序
中执行特定时间段内的单击和长按
利用它
package com.prac.com;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import io.appium.java_client.TouchAction;
import static io.appium.java_client.touch.TapOptions.tapOptions;
import static io.appium.java_client.touch.LongPressOptions.longPressOptions;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import static java.time.Duration.ofSeconds;
import static io.appium.java_client.touch.offset.ElementOption.element;
public class UdmeyCode extends Demo4TestBase {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver<AndroidElement> driver=Capabilities();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();
//Tap
TouchAction t =new TouchAction(driver);
WebElement expandList= driver.findElementByXPath("//android.widget.TextView[@text='Expandable Lists']");
t.tap(tapOptions().withElement(element(expandList))).perform();
driver.findElementByXPath("//android.widget.TextView[@text='1. Custom Adapter']").click();
WebElement pn= driver.findElementByXPath("//android.widget.TextView[@text='People Names']");
t.longPress(longPressOptions().withElement(element(pn)).withDuration(ofSeconds(2))).release().perform();
//Thread.sleep(2000);
System.out.println(driver.findElementById("android:id/title").isDisplayed());
}
}
我正在尝试对 Appium 中的 AndroidElement 执行长按操作。我发现我需要对此元素执行 TouchAction,但是......它只接受 WebDriver 作为参数,而不是我正在使用的 AndroidDriver。因此它不会工作。
TouchAction action = new TouchAction(AndroidDriver);
action.longPress(element, 10000);
我一直在寻找一些答案。 LongPress(或类似的东西)用于我现在正在写的最后一个测试。
解决方法是使用 io.appium.java_client.MultiTouchAction
。
MultiTouchAction multiTouch = new MultiTouchAction(AndroidDriver);
multiTouch.add(createTap(element, duration));
multiTouch.perform();
试试这个。
TouchAction action = new TouchAction();
action.longPress(webElement).release().perform();
下面的代码将在 android 应用程序
中执行特定时间段内的单击和长按利用它
package com.prac.com;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import io.appium.java_client.TouchAction;
import static io.appium.java_client.touch.TapOptions.tapOptions;
import static io.appium.java_client.touch.LongPressOptions.longPressOptions;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import static java.time.Duration.ofSeconds;
import static io.appium.java_client.touch.offset.ElementOption.element;
public class UdmeyCode extends Demo4TestBase {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver<AndroidElement> driver=Capabilities();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();
//Tap
TouchAction t =new TouchAction(driver);
WebElement expandList= driver.findElementByXPath("//android.widget.TextView[@text='Expandable Lists']");
t.tap(tapOptions().withElement(element(expandList))).perform();
driver.findElementByXPath("//android.widget.TextView[@text='1. Custom Adapter']").click();
WebElement pn= driver.findElementByXPath("//android.widget.TextView[@text='People Names']");
t.longPress(longPressOptions().withElement(element(pn)).withDuration(ofSeconds(2))).release().perform();
//Thread.sleep(2000);
System.out.println(driver.findElementById("android:id/title").isDisplayed());
}
}