gpt4 book ai didi

java - appium 中的 AndroidDriver 类型未定义方法 scrollTo(String)

转载 作者:行者123 更新时间:2023-11-28 20:52:05 28 4
gpt4 key购买 nike

我是 appium 测试工具的初学者,我尝试滚动到文本程序,但出现以下错误“AndroidDriver 类型未定义方法 scrollTo(String)”,

从那里我了解到“scrollTo”方法已贬值..对于我尝试过的以下代码是否有任何解决方案

package Android;
import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ScrollingToText {

AndroidDriver driver;

@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "0123456789ABCDEF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "5.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity","io.appium.android.apis.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void ScrollToText() throws InterruptedException {
//Scroll till element which contains "Views" text If It Is not visible on screen.
driver.scrollTo("Views");
// Click on Views/.
driver.findElement(By.name("Views")).click();
System.out.println("Scrolling has been started to find text -> Tabs.");
// Scroll till element which contains Tabs text.
driver.scrollTo("Tabs");
System.out.println("Tabs text has been found and now clicking on It.");
// Click on Tabs.
driver.findElement(By.name("Tabs")).click();
}

@AfterTest
public void End() {
driver.quit();
}
}

最佳答案

根据 github/appium #421 的评论之一

您应该能够使用

找到并滚动到 MobileElement
MobileElement radioGroup = driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"
+ ".resourceId(\"android:id/list\")).scrollIntoView("
+ "new UiSelector().text(\"Radio Group\"));");

还可以滚动到列表中的子元素,您可以使用 -

MobileElement radioGroup = list
.findElement(MobileBy
.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
+ "new UiSelector().text(\"Radio Group\"));"));

您可以在其中将 anroid:id/list 和文本 Radio Group 替换为所需元素的值。

来源 - findScrollabe()scrollingToSubElement()

编辑 - 对于任何寻求 iOS 帮助的人,IOSScrollingSearchingTest应该有助于做同样的事情。

关于java - appium 中的 AndroidDriver 类型未定义方法 scrollTo(String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42640868/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com