【发布时间】:2022-01-05 12:04:12
【问题描述】:
我正在学习 appium。在尝试在计算器上执行简单的单击功能时,我反复遇到相同的错误。这是代码
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
public class appiumtesttwo {
static AppiumDriver<MobileElement> driver;
public static void main(String[] args) {
try {
opencalculator();
} catch (Exception ex) {
// TODO: handle exception
System.out.println(ex.getCause());
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
public static void opencalculator() throws MalformedURLException {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "Lenovo TB-8504X");
cap.setCapability("udid", "HGAH50S4");
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "8.1.0");
cap.setCapability("appPackage", "com.android.calculator2");
cap.setCapability("appActivity", "com.android.calculator2.Calculator");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AppiumDriver<MobileElement>(url,cap);
System.out.println("App started");
MobileElement find = (MobileElement) driver.findElement( By.id("com.android.calculator2:id/digit_8"));
find.click();
System.out.println("completed");
}
}
计算器打开,但没有点击元素。
我得到的错误是
null
class org.openqa.selenium.remote.RemoteWebElement cannot be cast to class io.appium.java_client.MobileElement (org.openqa.selenium.remote.RemoteWebElement and io.appium.java_client.MobileElement are in unnamed module of loader 'app')
java.lang.ClassCastException: class org.openqa.selenium.remote.RemoteWebElement cannot be cast to class io.appium.java_client.MobileElement (org.openqa.selenium.remote.RemoteWebElement and io.appium.java_client.MobileElement are in unnamed module of loader 'app')
at appiumtesttwo.appiumtesttwo.opencalculator(appiumtesttwo.java:54)
at appiumtesttwo.appiumtesttwo.main(appiumtesttwo.java:22)
有点令人沮丧,因为如果不先解决它,我就无法进一步学习。我使用的 java-client 版本是 7.6.0,selenium-java 版本是 4.0.0。 提前致谢
【问题讨论】:
-
同样的错误我开始失去理智了,如果你有解决办法请更新
-
@Benjamin 仍然没有任何线索。如果找到任何东西,请告诉我。
标签: java selenium appium appium-android