【问题标题】:org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement with Appium and iOSorg.openqa.selenium.WebDriverException:返回值无法使用 Appium 和 iOS 转换为 WebElement
【发布时间】:2019-06-15 23:54:18
【问题描述】:

我面临的问题:无法将返回值转换为 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();

    }

}

控制台输出:

线程“main”中的异常 org.openqa.selenium.WebDriverException:返回值无法转换为 WebElement:{ELEMENT=4EE2A34-EE35-4F14-8EED-A33EEEEEE55} 构建信息:版本:'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.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

我的绒球。 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

【问题讨论】:

标签: java selenium appium appium-ios browserstack


【解决方案1】:

pom.xml 包含 Selenium v​​3.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 v​​3.6.0,因此您会看到错误:

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

解决方案

  • 清理你的项目工作区通过你的IDE和重建你的项目只需要依赖。
  • 执行您的@Test。

【讨论】:

    【解决方案2】:

    请有以下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>
    

    【讨论】:

      猜你喜欢
      • 2020-02-08
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 2018-12-03
      • 2016-08-16
      相关资源
      最近更新 更多