Java 在appium android automation中未找到MobileElement

Java 在appium android automation中未找到MobileElement,java,selenium,selenium-webdriver,appium,Java,Selenium,Selenium Webdriver,Appium,我将使用appium自动化android应用程序 配置: 应用程序版本:1.8.1 selenium服务器单机版:2.53.0 java客户端:4.1.2 实际上,当我运行脚本时,出现了一些错误 org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement 有谁能给出一个解决方案吗 我的代码: 您很可能使用的是不兼容版本的appium server 1.8.1是

我将使用appium自动化android应用程序

配置: 应用程序版本:1.8.1 selenium服务器单机版:2.53.0 java客户端:4.1.2

实际上,当我运行脚本时,出现了一些错误

org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement
有谁能给出一个解决方案吗

我的代码:


您很可能使用的是不兼容版本的appium server 1.8.1是最新版本,而client 4.1.2太旧

除非有充分的理由,否则不要显式设置selenium库,appium已经将其作为依赖项设置=>您可能会导致该操作出现问题

将appium java客户端版本更新为6.0.0

尝试清理代码:

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //set implicit wait first
WebDriverWait wait = new WebDriverWait(driver, 60); // now proceed with explicit wait 
WebElement smilyIcon = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("profile_overflow"))); // no need to put package, will be handled automatically; no need in casting as well, but try with latest client library - I had no issues on my side
smilyIcon.click();

您的应用程序是否已启动并在设备上运行?是。。它正在打开,突然关闭。我猜它无法检测到元素。但无法解决。你曾经遇到过这个问题吗?我很感谢,你能尝试使用像这样的驱动程序的元素id。findElementByIdprofile_overflow.click;为此,您必须使用testNG框架。您可以应用以下更改:-将Java客户端至少更改为5.01或5.0.4。
java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement
at app_automation.Sample.testMethod(Sample.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //set implicit wait first
WebDriverWait wait = new WebDriverWait(driver, 60); // now proceed with explicit wait 
WebElement smilyIcon = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("profile_overflow"))); // no need to put package, will be handled automatically; no need in casting as well, but try with latest client library - I had no issues on my side
smilyIcon.click();