Cannot find window with index: '1'

Hi, I am using Chrome browser to execute my test case. The scenario is after clicking a button, a new tab will open. So I need to switch tab by using WebUI.switchToWindowIndex(1). This doesn’t work for me. I have updated the WebDriver for Chrome already but still no luck.

Here’s the error message I received:

=============== ROOT CAUSE =====================
Caused by: com.kms.katalon.core.exception.StepFailedException: Cannot find window with index: ‘1’

For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshoot-common-execution-exceptions-web-test.html

11-23-2020 05:25:01 PM Test Cases/Forms/Building Forms

Elapsed time: 54.670s

Test Cases/Forms/Building Forms FAILED.
Reason:
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$11.call(Unknown Source)
at Building Forms.run(Building Forms:97)
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:339)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:330)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:309)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:301)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:235)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:191)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:141)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:90)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1606127069990.run(TempTestSuite1606127069990.groovy:39)
Caused by: com.kms.katalon.core.exception.StepFailedException: Cannot find window with index: ‘1’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToWindowIndexKeyword$_switchToWindowIndex_closure1.doCall(SwitchToWindowIndexKeyword.groovy:83)
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)
… 19 more

Thank you in advance!

I found a similar discussion:

The following fragment would be interesting:

int currentTab = WebUI.getWindowIndex()
...
WebUI.switchToWindowIndex(currentTab + 1)

Hi @kazurayam,
I have tried this method as well didn’t work for me. I am not sure now what to do.

I do not know anything about your Application Under Test, so that I have no more idea.

If you want others to help, you should provide more information so that other people can reproduce your problem on their side. See the following guidance:

At least I would require you to make the URL of your Application Under Test public so that I can see the page on my PC. If your AUT is private, then it would be very difficult for me to dig into your problem.

You may want to update the driver version:

@russel.sevilla
I got the same issue when I want to download a file from google driver when I click on download button, I was redirected to the download page but katalon I think is working on first tabe.
Try:

WebUI.switchToWindowIndex(0)

and then :

WebUI.switchToWindowIndex(1)

I got this issue too and with this method, I switched.

HI @costea.georgian89
Thanks for the input. I have tried this but it didn’t work for me. Anyway, I have made a workaround on my script, I just used navigate to URL keyword instead of switching. Thanks for the help!

1 Like