Returned value cannot be converted to WebElement

jayn picture jayn · May 22, 2018 · Viewed 7.4k times · Source

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

Answer

Suraj Jogdand picture Suraj Jogdand · May 23, 2018

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.