Brenda
Brenda

Reputation: 7

org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement with Appium and iOS

I am facing the issue : Returned value cannot be converted to WebElement. I am using BrowserStack as a cloud platform.

My appium code :

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();

    }

}

Console output :

Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {ELEMENT=4EE2A34-EE35-4F14-8EED-A33EEEEEEE55} 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 at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:375) at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62) at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) at io.appium.java_client.ios.IOSDriver.findElement(IOSDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473) at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:140) at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1) at io.appium.java_client.ios.IOSDriver.findElementByXPath(IOSDriver.java:1) at org.openqa.selenium.By$ByXPath.findElement(By.java:361) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360) at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58) at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) at io.appium.java_client.ios.IOSDriver.findElement(IOSDriver.java:1) at root.test123.main(test123.java:42) Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:373) ... 13 more Picked up _JAVA_OPTIONS: -Xmx512M

My pom . 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>

Note : I have already tried many online solutions.. along with the below one. https://discuss.appium.io/t/org-openqa-selenium-webdriverexception-returned-value-cannot-be-converted-to-webelement/18608

Upvotes: 1

Views: 4454

Answers (2)

shreeranga kv
shreeranga kv

Reputation: 27

Please have the following 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>

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193088

The pom.xml contains Selenium v3.141.59 dependency as follows:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

But as per the log messages:

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 

which indicates effectively Selenium v3.6.0 is being used and hence you see the error as:

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

Solution

  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Execute your @Test.

Upvotes: 2

Related Questions