我想从设置菜单中获取所有名称:https://app.screencast.com/AdssamooNLZbm?conversation=QUFAp0MrtNKXgm68k42Gfy&tab=Details
https://app.screencast.com/J4VoylbceDuca?conversation=Fodt4TO4fN1IVYW4zb9MKH&tab=Details
https://app.screencast.com/U0fnubCAhMjfW?conversation=wluK8dBoc2UkS6YRDqta1u&tab=Details
public static void main(String[] args) throws MalformedURLException, InterruptedException {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Redmi Note 9 Pro");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12.0");
dc.setCapability("appPackage", "com.android.settings");
dc.setCapability("appActivity", "com.android.settings.Settings");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(url, dc);
MobileElement list = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("+ "new UiSelector().text(\"Services & feedback\"));"));
Thread.sleep(5000);
List <WebElement> list2 = driver.findElementsById("android:id/title");
System.out.println(list2.size());
for (WebElement i : list2) {
System.out.println(i.getText());
}
}
}
But my Output:
10
Apps
Additional settings
Digital Wellbeing & parental controls
Special features
Mi Account
Google
Accounts & sync
Privacy
Location
Services & feedback
1条答案
按热度按时间guykilcj1#
从你所提供的来看,它只记录手机上显示的最后10条记录。
首先,对这段代码做一点解释:
它滚动到
Services & feedback
,等待5秒钟,然后捕获所有显示的元素,这些元素具有与List
对应的ID。因此,为了捕获具有所提供ID的所有元素,您可能需要重复以下过程,直到到达目的地:
请注意,您必须直接处理捕获的
WebElement
,如果您将WebElement
添加到List
中进行后续处理,则很可能会遇到StaleElementReferenceException
。