Unable to switch to window with index: ‘1’ on Edge

I am running edge on browserstack with katalon. When I try to use the switch to window index “1”, it will error. The test case works with chrome+browser stack, firefox with browser stack, and edge on my local.

The issue seems to be using katalon + edge + katalon+ switch window to index. Any ideas?

01-07-2021 03:51:19 PM switchToWindowIndex(“1”)

Elapsed time: 1.938s

Unable to switch to window with index: ‘1’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to switch to window with index: ‘1’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToWindowIndexKeyword.switchToWindowIndex(SwitchToWindowIndexKeyword.groovy:85)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToWindowIndexKeyword.execute(SwitchToWindowIndexKeyword.groovy:67)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.switchToWindowIndex(WebUiBuiltInKeywords.groovy:1888)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$switchToWindowIndex$5.call(Unknown Source)
at Footer - Privacy Statement.run(Footer - Privacy Statement:35)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:393)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:384)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:363)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:355)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:251)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1610056245957.run(TempTestCase1610056245957.groovy:25)
Caused by: org.openqa.selenium.InvalidArgumentException: invalid argument: ‘handle’ must be a string
(Session info: MicrosoftEdge=87.0.664.41)
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘207-254-10-131’, ip: ‘207.254.10.131’, os.name: ‘windows’, os.arch: ‘x86’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: driver.version: unknown
Command duration or timeout: 0 milliseconds
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 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at com.kms.katalon.selenium.driver.CRemoteWebDriver.execute(CRemoteWebDriver.java:30)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:903)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringTargetLocator.window(EventFiringWebDriver.java:718)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.switchToWindowUsingIndex(WebUiCommonHelper.java:176)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToWindowIndexKeyword$_switchToWindowIndex_closure1.doCall(SwitchToWindowIndexKeyword.groovy:79)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToWindowIndexKeyword$_switchToWindowIndex_closure1.call(SwitchToWindowIndexKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToWindowIndexKeyword.switchToWindowIndex(SwitchToWindowIndexKeyword.groovy:85)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToWindowIndexKeyword.execute(SwitchToWindowIndexKeyword.groovy:67)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.switchToWindowIndex(WebUiBuiltInKeywords.groovy:1888)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$switchToWindowIndex$5.call(Unknown Source)
at Script1608753160323.run(Script1608753160323.groovy:35)
… 11 more
Caused by: org.openqa.selenium.InvalidArgumentException: invalid argument: ‘handle’ must be a string
(Session info: MicrosoftEdge=87.0.664.41)
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘207-254-10-131’, ip: ‘207.254.10.131’, os.name: ‘windows’, os.arch: ‘x86’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: driver.version: unknown
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’

I think there’s an issue in the driver - that’s where the error is coming from.

Regardless, switchToWindowIndex takes and integer, not a string:

WebUI.switchToWindowIndex(1) // no quotes

Changing the string to an integer did fix edge 87, but not 86 or 85.

Which tells me the older drivers had bugs that were fixed in the newer driver.

I see. So this test case step is not usable for edge 86 and lower?

It would appear so based on your input.

Perhaps you can try another switch API?

I will investigate a bit more and let you know if I find anything helpful.

I tried URL and window title, and they both give me “Caused by: org.openqa.selenium.InvalidArgumentException: invalid argument: ‘handle’ must be a string”

my script is just
WebUI.switchToWindowUrl(‘https://www.theurl.com’)

seems to be an edge issue with katalon switch window?

I’m 99.99% certain that’s a driver bug. I think it showed up in geckodriver (Firefox) while ago. Maybe Edge’s driver has seen the same issue previously.

If you want to dig deeper, you can read this and maybe find solution…

Something I didn’t ask…

Are you waiting long enough for the new window to initialize? And indeed, is it a new window you’re trying to switch to?

yeah, i am waiting to give it some time to open the new window. And when I watch the video on browser stack, it opens fine.

Hmm. Okay. Try the stuff in that Stack Overflow link. Report back if you manage to figure it out - I’m sure someone else using browserstack to hit old browser versions will bump into this or similar.