org.openqa.selenium.WebDriverException:返回值无法通过Appium和iOS转换为W



我面临的问题是:返回的值无法转换为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.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-A33EEEEEEE55}构建信息:版本:"3.6.0",修订:"6fbf3ec767",时间:"2017-09-27T15:28:36.4Z"系统信息:主机:"V00XYZ",ip:"100.00.00100",os.name:"Windows 10",os.arch:"amd64",os.version:"10.0",java.version:"1.8.0_191"驱动程序信息:Driver.version:IOSDriver网址:org.openqa.selene.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:375)位于io.apium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)位于io.apium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)位于io.apium.java_client.ios.IOSDriver.findElement(IOSDriver.java:1)网址:org.openqa.selene.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)位于io.apium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:140)位于io.apium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)位于io.apium.java_client.ios.IOSDriver.findElementByXPath(IOSDriver.java:1)网址:org.openqa.selene.By$ByXPath.findElement(By.java:361)网址:org.openqa.selene.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)位于io.apium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)位于io.apium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)位于io.apium.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.selene.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:373)…还有13个拾取_JAVA_OPTIONS:-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>

注意:我已经尝试了许多在线解决方案。。以及下面的一个。https://discuss.appium.io/t/org-openqa-selenium-webdriverexception-returned-value-cannot-be-converted-to-webelement/18608

pom.xml包含Selenium v3.141.59依赖项,如下所示:

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>

但根据日志消息:

Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z' System info: host: 'V00XYZ', ip: '100.00.00.100', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191' 
Driver info: driver.version: IOSDriver 

这有效地表明正在使用Selenium v3.6.0,因此您看到的错误为:

org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement

解决方案

  • 通过IDE清理您的项目工作区,并仅使用所需的依赖项重建项目
  • 执行您的@Test

请提供以下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>

最新更新