question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can't find element when use 5.0.0 beta1,wrong:"java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement"

See original GitHub issue

Description

when I use 5.0.0beta1 java-client,I can’t find any element.the wrong is:

java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement

Environment

  • java client build version or git revision if you use some shapshot:5.0.0 beta1 from maven
  • Appium server version or git revision if you use some shapshot:1.6.0 and 1.6.3
  • Mobile platform/version under test:ios 10.2,xcode 8.2.1
  • Real device or emulator/simulator:real

Details

public class Test {

	private IOSDriver<MobileElement> driver = null;

	@BeforeClass
	public void beforeclass() {
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "IOS"); 
		capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest"); 
		capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "111"); 
		capabilities.setCapability(MobileCapabilityType.APP, "my app"); 
		capabilities.setCapability(MobileCapabilityType.UDID, "my udid"); 

		try {
			driver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void element() throws InterruptedException {
		Thread.sleep(10000);
		MobileElement element = (MobileElement) driver.findElement(By.className("XCUIElementTypeScrollView"));
		element.getSize();
		Thread.sleep(10000);
	}

	@AfterClass(alwaysRun = true)
	public void afterclass() {
		driver.quit();
	}
}

Ecxeption stacktraces

FAILED: element
java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement
	at com.haimi.HMLibrary.keywords.swipeTest.element(swipeTest.java:52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
	at org.testng.TestRunner.privateRun(TestRunner.java:767)
	at org.testng.TestRunner.run(TestRunner.java:617)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
	at org.testng.SuiteRunner.run(SuiteRunner.java:240)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
	at org.testng.TestNG.run(TestNG.java:1057)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0

Link to Appium logs

[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/6B9292D7-5B44-488B-9D68-5D8B90899294/element] with body: {“using”:“class name”,“value”:“XCUIElementTypeScrollView”} [debug] [JSONWP Proxy] Got response with status 200: {“value”:{“ELEMENT”:“22FC9416-0EB1-47CB-A800-019C566EC450”,“type”:“XCUIElementTypeScrollView”,“label”:null},“sessionId”:“6B9292D7-5B44-488B-9D68-5D8B90899294”,“status”:0} [debug] [MJSONWP] Responding to client with driver.findElement() result: {“ELEMENT”:“22FC9416-0EB1-47CB-A800-019C566EC450”,“type”:“XCUIElementTypeScrollView”,“label”:null}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:25 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
TikhomirovSergeycommented, Jan 3, 2017

@derunewige @SrinivasanTarget @saikrishna321 Ok. I can propose a PR. But there is some server side issue defenetely.

1reaction
itsnuwancommented, Aug 30, 2017

This issue got fixed in java-client-5.0.1.jar

Read more comments on GitHub >

github_iconTop Results From Across the Web

RemoteWebElement can not be cast to io.appium.java_client ...
Hi I am getting below error - Exception in thread “main” java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be ...
Read more >
Not able to locate element in chrome by using appium java
You are trying to cast a RemoteWebElement to one of its subclasses MobileElement. java.lang.ClassCastException Issue comes if you directly ...
Read more >
WindowsElement (java-client API) - Javadoc.io
java.lang.Object. org.openqa.selenium.remote.RemoteWebElement. io.appium.java_client.MobileElement. io.appium.java_client.windows.WindowsElement.
Read more >
"Returned value cannot be converted to WebElement ...
I was using following combination: Appium : 1.6.5 Selenium : selenium-java-3.3.1 Appium Java Client : java-client-5.0.3.
Read more >
appium/java-client - Gitter
WebDriverException: org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {stacktrace=NoSuchElementError: An element ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found