appium - 返回值无法转换为 WebElement

标签 appium appium-ios

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

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

Appium Java 客户端版本:6.0.0-BETA5

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

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

更新:

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

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。那是 Selenium 吗?什么是正确的方法?

    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

最佳答案

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

  <!-- 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 服务器版本时也遇到过类似的问题。

关于appium - 返回值无法转换为 WebElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50476030/

相关文章:

java - Appium 桌面 1.6.1> IOS> java : running desired capabilities gives bad

android - 关于selendroid和appium的几个问题

java - 使用 @AndroidFindBy 为具有多个 appPackage 的 android 运行 appium 测试

android - 我无法使用小米红米 4x 启动 Appium

java - 让司机闲置 15 分钟

java - XCUI测试: How to fetch List of elements from the iOS screen

阿皮姆 : Original error: -[XCUIElement resolve]: unrecognized selector sent to instance

java - Appium-如何使用Java从iOS设备读取日志

java - 如何在依赖于另一个下拉列表的selenium下拉列表中添加显式等待?

ios - 如何使用 Appium for IOS 在不关闭对话框的情况下隐藏键盘?