Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

appium - Returned value cannot be converted to WebElement

I'm using Appium for iOS Automation testing and I'm getting this error

Returned value cannot be converted to WebElement //*[@text='Search Results']

Appium Java client version: 6.0.0-BETA5

Downgrading java client is not an option for me as I'm using some methods from the latest beta version.

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

UPDATE:

I added selenium in my gradle like this:

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'
}

But when running tests, I still get the error. The build version here is 3.11.0. Is that Selenium? What is the right approach here?

    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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hi Please use following dependencies :

  <!-- 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> 

This should solve your problem, even i faced similar issue when i used different selenium server version.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...