Hi,
I’m trying to get all “interactable” elements from an self programmed App.
I have two methods:
List<MobileElement> interactableElements = driver.findElementsByXPath(".//*[@clickable='true' or @checkable='true' or @scrollable='true']");
and:
List<MobileElement> allItems = driver.findElementsByAndroidUIAutomator("new UiSelector()");
List<MobileElement> interactableElements = allItems.stream()
.filter(e -> Attributes.CLICKABLE.getFromBoolean(e) || Attributes.CHECKABLE.getFromBoolean(e) || Attributes.SCROLLABLE.getFromBoolean(e))
.collect(Collectors.toList());
I figured out, that the xpath method is faster…so I favor this.
However,
interactableElements.stream().forEach(e -> System.out.println(e.getText()));
gives me a
Cached elements 'By.xpath: .//*[@clickable='true' or @checkable='true' or @scrollable='true']' do not exist in DOM anymore
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: '*****', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-56- generic', java.version: '11.0.9.1'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: MainActivity, appPackage: ****..., automationName: UiAutomator2, clearDeviceLogsOnStart: true, databaseEnabled: false, desired: {appActivity: MainActivity, appPackage: ****..., automationName: UiAutomator2, clearDeviceLogsOnStart: true, disableWindowAnimation: true, newCommandTimeout: 1200, platformName: android, udid: emulator-5558}, deviceApiLevel: 30, deviceManufacturer: Google, deviceModel: sdk_gphone_x86_arm, deviceName: emulator-5558, deviceScreenDensity: 420, deviceScreenSize: 1080x1920, deviceUDID: emulator-5558, disableWindowAnimation: true, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, newCommandTimeout: 1200, pixelRatio: 2.625, platform: LINUX, platformName: Android, platformVersion: 11, statBarHeight: 63, takesScreenshot: true, udid: emulator-5558, viewportRect: {height: 1731, left: 0, top: 63, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 73114860-dd23-4709-9f43-4f3ccac05ac1
....
with the xpath method and works flawlessly with the second UIAutomator method.
Also, trying out to get any attribute from an element gives me this error.
Appium java-client 7.4.1, appium version 1.19.1
Best Regards