I can’t find a way to import MobileElement for code I copy after following this guide: https://www.youtube.com/watch?v=i1tQ1pjEFWw&t=1915s&ab_channel=edureka%21 in Appium for testing Android.
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileElement;
public class Test {
public static void main(String args[]){
MobileElement el3 = (MobileElement) driver.findElementById("com.example.calculator:id/button2");
el3.click();
MobileElement el4 = (MobileElement) driver.findElementById("com.example.calculator:id/button5");
el4.click();
MobileElement el5 = (MobileElement) driver.findElementById("com.example.calculator:id/buttonPlus");
el5.click();
MobileElement el6 = (MobileElement) driver.findElementById("com.example.calculator:id/button3");
el6.click();
MobileElement el7 = (MobileElement) driver.findElementById("com.example.calculator:id/button9");
el7.click();
}
}
But the recorded code has MobileElement, so I do the same by downloading libraries from this site: http://appium.io/downloads.html.
This is my library which was downloaded from appium.io
But later, it showed me that it doesn’t have MobileElement library, so I can’t import it.
Cannot resolve symbol ‘MobileElement’
Is it because the code is old or does the library have an update that I don’t know?
2
Answers
I am doing the same thing. My solution is to switch to released java-client, not the beta version.
Good luck
Appium java-client v8 uses Selenium4 and introduces a lot of breaking changes.
You can look here
https://github.com/appium/java-client/blob/master/docs/v7-to-v8-migration-guide.md#mobileelement.
It’s recommended to use WebElement interface type instead of MobileElement.
Appium java-client v8 seems to be W3C compliant. So moving to a new API is a step into the future. At least after final 8.0.0 release (it’s beta right now).