【问题标题】:Returned value cannot be converted to WebElement返回值无法转换为 WebElement
【发布时间】:2018-11-01 17:09:21
【问题描述】:

我正在使用 Appium 进行 iOS 自动化测试,但出现此错误

返回值无法转换为 WebElement //*[@text='Search Results']

Appium Java 客户端版本:6.0.0-BETA5

降级 java 客户端对我来说不是一个选项,因为我使用的是最新 beta 版本中的一些方法。

try {
        MobileElement titleView = navigationBar.findElement(By.xpath("//*[@text='" + title + "']"));
        return titleView.isDisplayed();
    }

更新:

我像这样在我的 gradle 中添加了硒:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'io.appium:java-client:6.0.0-BETA5'
implementation 'org.seleniumhq.selenium:selenium-server:3.9.1'

implementation "com.google.code.gson:gson:2.8.2"
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

compileOnly 'org.projectlombok:lombok:1.16.20'
annotationProcessor 'org.projectlombok:lombok:1.16.20'

testImplementation 'junit:junit:4.12'
}

但是在运行测试时,我仍然得到错误。这里的构建版本是 3.11.0。是硒吗?这里的正确方法是什么?

    org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: //*[@text='Search Results']
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'USGPSNYCM212943.local', ip: 'fe80:0:0:0:462:ed8d:f2e4:f85d%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_152-release'
Driver info: driver.version: unknown

【问题讨论】:

    标签: appium appium-ios


    【解决方案1】:

    您好,请使用以下依赖项:

      <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
            <dependency>
                <groupId>io.appium</groupId>
                <artifactId>java-client</artifactId>
                <version>6.0.0-BETA5</version>
            </dependency>
     <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-server</artifactId>
                <version>3.9.1</version>
            </dependency> 
    

    这应该可以解决您的问题,即使我在使用不同的 selenium 服务器版本时也遇到了类似的问题。

    【讨论】:

    • 谢谢,我如何在 gradle 中做到这一点?我对此很陌生
    • 更新了我上面的问题,请指出我做错了什么。
    • 嗨@Suraj,我也面临着与上述依赖项相同的问题:org.seleniumhq.seleniumselenium-java3.9.1 但得到同样的错误。
    【解决方案2】:

    我在这个问题上苦苦挣扎了几天。我尝试了各种论坛上提到的所有解决方案,例如升级或降级 appium 版本等。最后,通过在驱动程序对象上添加一个简单的 5 秒隐式等待解决了这个问题。如果您遇到此问题,请尝试一下。

    【讨论】:

      【解决方案3】:

      如果有人现在看到这个,那么 WebElement 搜索取决于您使用的驱动程序。

      如果使用 AndroidDriver,则将泛型类型称为 AndroidDriver 驱动程序; driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), 能力);

      如果使用 appiumDriver,则将泛型类型称为 AppiumDriver 驱动程序; driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), 能力);

      希望对你有帮助!

      【讨论】:

        【解决方案4】:

        在 Desired Capabilities 添加以下附加功能,它应该可以工作:

        capability.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "60");
        

        【讨论】:

          【解决方案5】:

          我正在使用

          Appium-windows-1.13.0
          java-client-5.0.0-BETA6
          

          我已经更新到

          Appium-windows-1.15.1
          java-client-6.0.0-BETA4
          

          成功了

          【讨论】:

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