Java org.openqa.selenium.WebDriverException:返回的值不能用Appium和iOS转换为WebElement
我面临的问题是:返回值无法转换为WebElement。 我使用BrowserStack作为云平台 我的应用程序代码:Java org.openqa.selenium.WebDriverException:返回的值不能用Appium和iOS转换为WebElement,java,selenium,appium,appium-ios,browserstack,Java,Selenium,Appium,Appium Ios,Browserstack,我面临的问题是:返回值无法转换为WebElement。 我使用BrowserStack作为云平台 我的应用程序代码: package root; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import io.appium.java_client
package root;
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.ios.IOSDriver;
public class test123 {
public static void main(String[] args) throws MalformedURLException, InterruptedException
{
String userName="brenda467";
String accessKey="adfadfadfadf";
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserstack.user", userName);
caps.setCapability("browserstack.key", accessKey);
caps.setCapability("platform","iOS");
//caps.setCapability("platformName","iOS");
caps.setCapability("deviceName","iPhone 7");
caps.setCapability("os_version","10.3");
caps.setCapability("app","bs://asfasdfasfasdfasfa");
caps.setCapability("browserstack.debug",true);
caps.setCapability("automationName","XCUITest");
//caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "60");
caps.setCapability("noReset", true);
AppiumDriver driver = new IOSDriver(new URL("http://hub.browserstack.com/wd/hub/"), caps);
Thread.sleep(900);
driver.findElement(By.xpath("//XCUIElementTypeOther[@name='LOG IN']")).click();
}
}
控制台输出:
线程“main”org.openqa.selenium.WebDriverException中出现异常:返回值无法转换为WebElement:{ELEMENT=4EE2A34-EE35-4F14-8EED-A33EEE55}
构建信息:版本:“3.6.0”,修订版:“6fbf3ec767”,时间:“2017-09-27T15:28:36.4Z”
系统信息:主机:'V00XYZ',ip:'100.00.00.100',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'1.8.0_191'
驱动程序信息:Driver.version:IOSDriver
位于org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:375)
位于io.appium.java_client.DefaultGenericMobileDriver.findelelement(DefaultGenericMobileDriver.java:62)
位于io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
位于io.appium.java_client.ios.IOSDriver.findElement(IOSDriver.java:1)
位于org.openqa.selenium.remote.RemoteWebDriver.findelementbypath(RemoteWebDriver.java:473)
位于io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:140)
位于io.appium.java_client.AppiumDriver.findelementbypath(AppiumDriver.java:1)
位于io.appium.java_client.ios.IOSDriver.findelementbypath(IOSDriver.java:1)
位于org.openqa.selenium.By$ByXPath.findElement(By.java:361)
位于org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
位于io.appium.java_client.DefaultGenericMobileDriver.findelelement(DefaultGenericMobileDriver.java:58)
位于io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
位于io.appium.java_client.ios.IOSDriver.findElement(IOSDriver.java:1)
位于root.test123.main(test123.java:42)
原因:java.lang.ClassCastException:java.util.HashMap无法转换为org.openqa.selenium.WebElement
位于org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:373)
... 还有13个
拾取的JAVA选项:-Xmx512M
我的pom。xml:
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
木卫一
pom.xml包含Selenium v3.141.59依赖项,如下所示:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
这表明正在有效地使用Selenium v3.6.0,因此您会看到以下错误:
org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement
解决方案
- 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
- 执行
@测试
请提供以下POM
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>Test</groupId>
<artifactId>AppiumProject</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
测试
应用项目
1.0-快照
org.apache.maven.plugins
maven编译器插件
8.
8.
木卫一
java客户端
5.0.3
org.seleniumhq.selenium
硒爪哇
3.3.1
尝试使用AppiumDriver驱动程序而不是**AppiumDriver驱动程序请按照此处的链接进行操作!!请按照链接中的答案进行操作
<groupId>Test</groupId>
<artifactId>AppiumProject</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>