0

TL;DR

I give my function a string. It complains that what I gave it isn't a string.


My code:

new WebDriverWait(driver, 5).until(ExpectedConditions.numberOfWindowsToBe(1));  //induce WebDriverWait
System.out.println(driver.getWindowHandle());
String nameWindow = driver.getWindowHandle();
driver.switchTo().window(nameWindow);// Force Focus
element.click();

What the System.out.println() return: CDwindow-0

The error message I get:

The code fail with the line driver.switchTo().window(nameWindow);. Here is the error message:

org.openqa.selenium.InvalidArgumentException: invalid argument: 'name' must be a string
  (Session info: chrome=83.0.4103.106)
  (Driver info: chromedriver=83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103@{#119}),platform=Linux 4.15.0-52-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PC-ABCD', ip: '192.168.224.31', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {browserName: Chrome, chromeOptions: {args: [--proxy-server=10.0.2.2:8080, --proxy-bypass-list=<-loopb...]}, databaseEnabled: false, desired: {browserName: Chrome, chromeOptions: {args: [--proxy-server=10.0.2.2:8080, --proxy-bypass-list=<-loopb...]}, deviceName: Galaxy S9, deviceReadyTimeout: 120, fullReset: false, headless: false, launchTimeout: 300, nativeWebScreenshot: true, newCommandTimeout: 300, performance: false, platform: ANY, platformName: Android, platformVersion: 8, shutdownOtherSimulators: true, useNewWDA: true, waitForQuiescence: false, wdaLaunchTimeout: 120000}, deviceManufacturer: Google, deviceModel: Android SDK built for x86, deviceName: emulator-5554, deviceReadyTimeout: 120, deviceScreenSize: 1440x2960, deviceUDID: emulator-5554, fullReset: false, headless: false, javascriptEnabled: true, launchTimeout: 300, locationContextEnabled: false, nativeWebScreenshot: true, networkConnectionEnabled: true, newCommandTimeout: 300, performance: false, platform: ANY, platformName: Android, platformVersion: 8.0.0, shutdownOtherSimulators: true, takesScreenshot: true, useNewWDA: true, waitForQuiescence: false, warnings: {}, wdaLaunchTimeout: 120000, webStorageEnabled: false}
Session ID: 15a42994-07c0-426c-b811-c502c48e4e7d
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:903)
    at souscription.Stepdefs.iClickOnElement(Stepdefs.java:560)

What I tried to fix it:

new WebDriverWait(driver, 5).until(ExpectedConditions.numberOfWindowsToBe(1));  //induce WebDriverWait
try {
    Thread.sleep(500);
} catch (InterruptedException e) {
    e.printStackTrace();
}
System.out.println(driver.getWindowHandle());
String nameWindow = driver.getWindowHandle();
driver.switchTo().window("CDwindow-0");// Force Focus
element.click();

But I still get the very same error message. Even though I am literally given the function a string.

My configuration:

Java "1.8.0_191", Selenium 3.141.59, Appium Java client 7.3.0, Appium 1.11.1, Android Galaxy S9

Question:

Any idea how I can fix that? I need to make sure that I have the right window in focus before making my click and if the "switchTo" doesn't work, that's an issue.

6
  • Your issue starts from here souscription.Stepdefs.iClickOnElement(Stepdefs.java:560). Are you sure you're showing us the right piece of code?
    – Alexey R.
    Feb 9, 2021 at 11:20
  • @AlexeyR. Yes, I'm sure Feb 9, 2021 at 11:22
  • Can you check what is the version of Appium itself? You only show the version of java client for appium.
    – Alexey R.
    Feb 9, 2021 at 11:44
  • @AlexeyR. It's Appium 1.11.1 Feb 9, 2021 at 13:15
  • (Stepdefs.java:560) what is there in that line ?
    – PDHide
    Feb 9, 2021 at 16:09

3 Answers 3

1

Try to update your Appium build. Here is the issue discussed. Seems that you have old Appium. The latest one is 1.20.2.

The problem is how Appium proxies the request from the Java client to the actual web driver. The latest version has to have this fixed.

3
  • So, I tried updating appium but it didn't change anything (I did turn my IDE off and on again to make sure that the changes were taken into account). But you might be right about updating stuff. So I should probably update everything (including the Chrome driver) and see how it goes. Feb 9, 2021 at 14:00
  • As far as I have known from that thread and related ones is that chromedriver works fine for this use case. At least you are using the driver compatible with the browser.
    – Alexey R.
    Feb 9, 2021 at 14:07
  • @BelovedFool can you get appium debug-level logs as that guy attached to his issue on github?
    – Alexey R.
    Feb 9, 2021 at 14:09
0

https://github.com/appium/java-client/issues/970

forceMjsonwp:true

could you try in set capabiities?

capabilities.setCapability("forceMjsonwp ", true)

it seems an issue with chrome , you can try updating chrome or forcing appium to use JSON wire protocol instead of w3c

0

You can use the next lines to switch window:

ArrayList "Objetc (windows)" = new ArrayList(driver.getWindowHandles()); "webDriver".swithchTo().window(objeto.get("WindowNumber").toString());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.