我正面临一个问题:返回值无法转换为WebElement。 我正在使用BrowserStack作为云平台。
我的appium代码:
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();
}
}
控制台输出:
线程“主”中的异常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.00.100',操作系统名称:'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.findElement(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.findElementByXPath(RemoteWebDriver.java:473) 在io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:140) 在io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1) 在io.appium.java_client.ios.IOSDriver.findElementByXPath(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.findElement(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_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
答案 0 :(得分:2)
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
@Test
。答案 1 :(得分:0)
请具有以下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>