JavascriptExecutor execute on Android - Chrome Browser

Hi Team,

I would like to click on element using JavascriptExecutor.

I am able to click on element with command:
driver.findElement(By.xpath("//android.widget.Button[@text=‘Play’]")).click();

This command execution takes time in between 10-25 seconds. This is slowing down test case execution process.

I would like to click do this operation using JavascriptExecutor.

Here is code for reading text using JavaScriptExecutor and exception
0
down vote
favorite

I am trying to perform read text from Android - Chrome Browser using JavascriptExecutor.

My code: String videoDurationValue = javascriptExecutor.executeScript( “var value = “document.evaluate(”//*[@id=‘my-video’]/div[5]/div[7]/div”, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML; return value.stringValue;").toString();

But getting error - org.openqa.selenium.WebDriverException: Method is not implemented

Appium version 1.8.1

How can I do the same? Please do let me know.

Thanks,

Deepak

DiverSity Tech

@Rajesh_RK

Hi Rajesh,

Did you manage to look into the issue?

Thanks,
Deepak

Hey Deepak/@TechTeam,

Actually i was busy with my work so unable to look into issue.

Hope Library which u have used is not supported. May be u need to change JavaClient jar file. Meanwhile can u try with below thing

	JavascriptExecutor js = (JavascriptExecutor) remoteDriver;
            WebElement element = remoteDriver.findElementByXPath(xpath);
           js.executeScript("return arguments[0].text", element);

Thanks,
Rajesh Kumar

Thanks Rajesh I will check.

Do you have any idea about this error

I upgraded Appium to version 1.9.0. Appium Java Client 6.1.0.

Working OS: Windows 10

org.openqa.selenium.WebDriverException: It is impossible to create a new session because ‘createSession’ which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: ‘3.14.0’, revision: ‘aacccce0’, time: ‘2018-08-02T20:19:58.91Z’
Driver info: driver.version: AppiumDriver
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:195)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:130)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94)
at com.artm.automation.TestVideoAdAndroidMain.main(TestVideoAdAndroidMain.java:72)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:185)
… 11 more
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: The desired capabilities must include either ‘appPackage’ or ‘browserName’

remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: The desired capabilities must include either ‘appPackage’ or ‘browserName’
at getResponseForW3CError (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:824:9)
at asyncHandler$ (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:375:37)
at tryCatch (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:122)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:125)
… 16 more

Hey Deepak/@TechTeam,

Please include below desired capabilities in your code

This is for Android and change as per your automation requirement

dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, appPackage);
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, appActivity);

Thanks a lot Rajesh. I will try with above capabilities.

Thanks a lot for all your support & help.

Hey Deepak /@TechTeam

Is it working?

Thanks,
Rajesh Kumar