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


#1

public class Call1 {

public static void main(String[] args) {
	try
	{
		DesiredCapabilities capabilities = new DesiredCapabilities();
	    capabilities.setCapability("autoAcceptAlerts","true");
	    capabilities.setCapability("automationName","Appium");
		capabilities.setCapability("platformName","Android");
		capabilities.setCapability("platformVersion","6.0");
		capabilities.setCapability("deviceName","35b4ac187d63");
		capabilities.setCapability("appPackage", "com.android.contacts");
		capabilities.setCapability("appActivity", "com.android.contacts.activities.TwelveKeyDialer");
	    	    
	    AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
	    
	    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
	    Thread.sleep(2000);
	 
	    driver.findElement(By.id("com.android.contacts:id/one")).click();
		
	}catch(Exception e)
	{
		e.printStackTrace();
	}

}

}

and the error is
Sep 07, 2017 12:12:35 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel’s Law holds true on the remote end
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Sep 07, 2017 12:12:59 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {ELEMENT=1}
Build info: version: ‘unknown’, revision: ‘1969d75’, time: ‘2016-10-18 09:43:45 -0700’
System info: host: ‘Admin-PC’, ip: ‘192.168.0.186’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_92’
Driver info: driver.version: AndroidDriver
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.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:417)
at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:70)
at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)
at org.openqa.selenium.By$ById.findElement(By.java:218)
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.android.AndroidDriver.findElement(AndroidDriver.java:1)
at pack3.Call1.main(Call1.java:34)
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

The is in this line ------ driver.findElement(By.id(“com.android.contacts:id/one”)).click();


For IOS : Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement
#2

@JithendraKumarCS check - https://github.com/appium/java-client/issues/709


#3

i have not used any pom or testng xml files


#4

@JithendraKumarCS but you use some version of JAVA-CLIENT that is affected.


#5

So can I use old java client


#6

@JithendraKumarCS better move to latest 5.0.2. which one you have now?


#7

I have 5.0.1 java client


#8

@JithendraKumarCS so try latest 5.0.2 -> not help -> change your selenium versions as suggested in link


#9

As you suggested I changed the selenium version now I am not getting any error but not able to click on the element. I tried element.isDisplayed() method it is showing but not able click on the element.
Can u help on in this?


#10

WebElement ele=driver.findElement(By.className(“android.widget.ImageButton”));
if(ele.isDisplayed())
{
System.out.println(" class is present");
WebElement ele1=driver.findElementById(“com.android.contacts:id/one”);
if(ele1.isDisplayed())
{
System.out.println(“1 --”);
ele1.click();
}

	    	WebElement ele2=driver.findElementById("com.android.contacts:id/nine");
	    	if(ele2.isDisplayed())
	    	{
	    		System.out.println("2 --");
	    		ele2.click();
	    	}
	    	
	    	WebElement ele3=driver.findElementById("com.android.contacts:id/eight");
	    	if(ele3.isDisplayed())
	    	{
	    		System.out.println("3 --");
	    		ele3.click();
	    	}
	    }else{
	    	System.out.println(" class is not present");
	    }

O/P

class is present
1 –
2 –
3 –


#11

@JithendraKumarCS try to change code like:


        WebElement ele3 = driver.findElement(MobileBy.id("com.android.contacts:id/eight"));
        new TouchAction((MobileDriver) driver).press(ele3).waitAction(Duration.ofMillis(70)).release().perform();

#12

Sorry for late reply… I tried but getting the below error

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘unknown’, revision: ‘unknown’, time: ‘unknown’
System info: host: ‘ADMIN-PC’, ip: ‘192.168.43.194’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_92’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.android.contacts, deviceScreenSize=720x1280, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=35b4ac187d63, platform=LINUX, deviceUDID=35b4ac187d63, appActivity=com.android.contacts.activities.TwelveKeyDialer, desired={appPackage=com.android.contacts, appActivity=com.android.contacts.activities.TwelveKeyDialer, platformVersion=6.0, automationName=Appium, platformName=Android, deviceName=35b4ac187d63, autoAcceptAlerts=true}, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, takesScreenshot=true, javascriptEnabled=true, deviceModel=Redmi 3S, deviceManufacturer=Xiaomi, platformName=LINUX, autoAcceptAlerts=true}]
Session ID: f3a89336-880c-4c2b-b1c9-f5603e812788
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.PerformsTouchActions.performTouchAction(PerformsTouchActions.java:41)
at io.appium.java_client.TouchAction.perform(TouchAction.java:325)
at pack3.Call1.main(Call1.java:87)


#13

Did you find any resolution to the issue. I am also facing the same issue.


#14

No I tried with so many options, at last even re-install each and every software but not able to resolve the issue. If you get any solution please post the code or fixed patch


#15

Hi,

I was using following combination:
Appium : 1.6.5
Selenium : selenium-java-3.3.1
Appium Java Client : java-client-5.0.3

I downgraded the Appium client to
Appium Java Client : java-client-5.0.0-BETA6

and the problem was solved.

I am not aware how/where to raise the issue of the version incompatibility issue.

@JithendraKumarCS please try and confirm if it works for you.


#16

Appium : 1.6.5
Selenium : selenium-java-3.3.1
Appium Java Client : java-client-5.0.0-BETA6

I used this combination, same problem…
It is able find the element but not able to click on the dail pad

did really combination of jar file b/w Selenium and appium matters?
Becoze whenever I change the jar file it gives different errors…


#17

Yes, Combination of versions of selenium and appium client matters a lot. I am facing so many issues. Almost new issues with any APP i look to automate. Some links suggest to downgrade even selenium to lower version instead of 3.3.


#18

This is very bad, means how we can judge the compatible jar files b/w Appium and selenium…
From past 2 week I stuck with same problem…
Please if any have the solution on this???


#19

Can anyone provide me the code to click on dail pad in mobile and required jar file versions
finally, screen shot of sdk manager to show what are all installed in it ?


#20

@JithendraKumarCS can you post your code FULL all including imports at https://gist.github.com/ and share link?