'Cannot find findelementbyandroiduiautomator method for appium android driver

I am using android driver with mobileElement typecast, but I cannot find the findelementbyandroiduiautomator method in my list of methods. All the other methods are not inspecting any elements on my app, this looks like my last resort.

driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), cap);

The Compiler error I get when I try to use the method is this: findelementbyandroiduiautomator method not found for driver.



Solution 1:[1]

If you are using Appium Java client version above 6, Please try the below code

AndroidDriver driver=new AndroidDriver(new URL(""), cap); driver.findElement(MobileBy.AndroidUIAutomator("")).click();

Solution 2:[2]

If you are using reference variable of WebDriver or AppiumDriver, then you need to downcast the driver to AndriodDriver in order to access findElementByAndroidUIAutomator() method. Because this method is specific to AndriodDriver and not available in parent classes or interfaces. e.g.:

WebDriver driver =  = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
((AndroidDriver) driver).findElementByAndroidUIAutomator("some expression").click();

Note: This downcasting is not required, if you directly use reference of AndroidDriver. e.g.:

AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
driver.findElementByAndroidUIAutomator("some expression").click();

Solution 3:[3]

Because findElementByAndroidUIAutomator is a default method which is supported by Java 8 onward. Please check your java version in the project. Change it to 1.8+.

Right click on the project -> Properties -> check JRE library version and Double click on JRE System library to change -> Change JRESE-1.8 

You will get the findElementByAndroidUIAutomator with driver object.

Solution 4:[4]

try the below code, it worked for me:

driver.findElement(new AppiumBy.ByAndroidUIAutomator("attribute(\"Value\")")).click();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kavi
Solution 2
Solution 3 rahul jathar
Solution 4