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.

SwitchTo or Window handle is failing when it is executed through webdriver.io

See original GitHub issue

The problem

When we perform a switchTo or window operations from webdriver.io, the POST call made to appium server contains two parameters {"name":"1","handle":"1"}. And appium servers are throwing an error back saying Parameters were incorrect. We wanted {"required":["name"]} and you sent ["name","handle"].

Environment

Appium Version: 1.7.2 Mac OS : 10.12.6 Node: 8.6.0 Mobile device: iPhone 7(real device) with OS 11.2.6

Details

When we make an switchTo or Window handle from webdriver.io, then it passes the below params to appium server: Logs:

[21:40:08]  COMMAND	GET 	 "/wd/hub/session/00353d5d-b470-43da-9e56-19e2dc603f4c/window_handles"
[21:40:08]  DATA		{}
[21:40:08]  RESULT		["1"]
[21:40:08]  COMMAND	POST 	 "/wd/hub/session/00353d5d-b470-43da-9e56-19e2dc603f4c/window"
[21:40:08]  DATA		{"name":"1","handle":"1"}

When it reached the appium server, i can see the below logs:

[HTTP] --> POST /wd/hub/session/00353d5d-b470-43da-9e56-19e2dc603f4c/window {"name":"1","handle":"1"}
[debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["name"]} and you sent ["name","handle"]
[HTTP] <-- POST /wd/hub/session/00353d5d-b470-43da-9e56-19e2dc603f4c/window 400 2 ms - 89 

So it looks like, appium server is so strict that it accepts only name.

Here is the simple sample code to switchTo a window in wdio:

var wins = browser.windowHandles();
        console.log('WINDOWS: ' + wins.value.length);
        console.log('WINDOWS: ' + wins.value[0]);
        for(let i=0; i<wins.value.length; i++){
            browser.window(wins.value[i]);
            console.log('A switch is performed');
        } 

NOTE: The same switching windows works fine through Java with selenium. There appium server gets only name in the params.

Thanks, Naveen.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
NaveenThiyagarajancommented, May 8, 2018

Hi Team, Could someone please provide an update. This is blocking from automating a app that switches to browser.

0reactions
lock[bot]commented, Aug 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

selenium webdriver - Error using Windows Handle Selelnium
switchTo ().window((String) handle[1]);. The array that you created doesn't has element at index 1, and so it throws this error.
Read more >
webdriverio/webdriverio - Gitter
switchToWindow(windowHandle[1]); it seems like the window handle has been switched correctly, but once I am on the new window, none of my elements...
Read more >
WebDriver Protocol | WebdriverIO
The Get Window Handle command returns the window handle for the current top-level browsing context. It can be used as an argument to...
Read more >
Working with windows and tabs
Get window handle ... WebDriver does not make the distinction between windows and tabs. If your site opens a new tab or window,...
Read more >
Handle Multiple Windows in Selenium Webdriver using ...
Switch to second window then call page object methods corresponding to pages available in 2nd window. Similarly when you have to switch back...
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