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.
souscription.Stepdefs.iClickOnElement(Stepdefs.java:560)
. Are you sure you're showing us the right piece of code?