Hi there,
I am having an issue while running the following code,it’s throwing
“Exception in thread “main” java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class io.appium.java_client.MobileElement (java.util.ArrayList is in module java.base of loader ‘bootstrap’; io.appium.java_client.MobileElement is in unnamed module of loader ‘app’)
at appium.AppiumTest.main(AppiumTest.java:42)”
Any help would be appreciated,thanks.
package appium;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebElement;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
public class AppiumTest {
public static void main(String[] args) {
//Set the Desired Capabilities
File app= new File("C:\\Users\\ikabir\\Desktop\\Andriod-apk\\fbc.mobile.MemberApp.Droid-Signed.apk");
DesiredCapabilities caps = new DesiredCapabilities();
//caps.setCapability("udid", "ENUL6303030010"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "7.0");
caps.setCapability("deviceName", "Galaxy S6");
caps.setCapability("app", app.getAbsolutePath());
//caps.setCapability("appPackage", "com.android.vending");
//caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
caps.setCapability("appPackage", "Test");
//caps.setCapability("automationName", "UiAutomator2");
//caps.setCapability("appActivity", "test.mobile.MemberApp.Droid/test.mobile.MemberApp.Droid.MainActivity");
caps.setCapability("noReset", "true");
//Instantiate Appium Driver
try {
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
MobileElement emailinput = (MobileElement) driver.findElementsByAccessibilityId(“mailEntry”);
emailinput.click();
emailinput.sendKeys(“[email protected]”);
driver.closeApp();
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
}