org.openqa.selenium.NoSuchWindowException: no such window: window was already closed

Hi Team,

I am getting below error while clicking on Look up button in SFDC. It was working properly earlier but suddenly all my testing got stuck due to this issue.
I have used manual keyword for this click (Refer script of the button)

package com.general

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement
import org.openqa.selenium.interactions.Actions as Actions
import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebUiCommonHelper
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor

import internal.GlobalVariable

import MobileBuiltInKeywords as Mobile
import WSBuiltInKeywords as WS
import WebUiBuiltInKeywords as WebUI

public class Click {

@Keyword
def clickUsingJS(TestObject to, int timeout){
	WebDriver driver = DriverFactory.getWebDriver()
	WebElement element = WebUiCommonHelper.findWebElement(to, timeout)
	JavascriptExecutor executor = ((driver) as JavascriptExecutor)
	executor.executeScript('arguments[0].click()', element)
}

}

Please check and reply. Thanks.

Screenshot-

Error-
04-09-2019 05:12:02 PM Test Cases/BSSE/InstaCC_Global/InstaCC
Elapsed time: 2m - 48.592s
com.general.Click.clickUsingJS:39

com.general.Click.invokeMethod:0

Test Cases/BSSE/InstaCC_Global/InstaCC FAILED.
Reason:
org.openqa.selenium.NoSuchWindowException: no such window: window was already closed
(Session info: chrome=73.0.3683.86)
(Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘TCL-5106126’, ip: ‘172.16.5.48’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.43.600210 (68dcf5eebde371…, userDataDir: C:\Users\rtakwale\AppData\L…}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:49510}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 73.0.3683.86, webStorageEnabled: true}
Session ID: 708dac17cd292c6f6ca15f2ca4e9d8c5
*** Element info: {Using=xpath, value=//span[@id=‘CityLookup_0_ctrlButtons’]//img[@alt=‘Lookup CityLookup’]}
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:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:20)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:397)
at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:476)
at org.openqa.selenium.By$ByXPath.findElements(By.java:356)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:358)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElements(WebUiCommonHelper.java:739)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:996)
at com.kms.katalon.core.webui.common.WebUiCommonHelper$findWebElement.call(Unknown Source)
at com.general.Click.clickUsingJS(Click.groovy:39)
at com.general.Click.invokeMethod(Click.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
at Configure_Site1_Mumbai.run(Configure_Site1_Mumbai:50)
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:321)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:312)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:291)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:283)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:222)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:54)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:80)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)
at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
at InstaCC.run(InstaCC:32)
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:321)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:312)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:291)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:283)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:222)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1554810119427.run(TempTestCase1554810119427.groovy:22)

Can you post the code from the Test Case?

Dear Russ,
Thanks for your reply :slight_smile::grinning:

Here is the code from test case. Please tell me if any more inputs require from me.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

WebUI.click(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/New_Product_Configuration_Button’))

WebUI.click(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/InstaCC_Global_Category’))

WebUI.waitForPageLoad(GlobalVariable.Timeout)

WebUI.click(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Site_End_Point’))

WebUI.waitForPageLoad(GlobalVariable.Timeout)

WebUI.waitForElementNotVisible(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Loading_Indicator_Block’), GlobalVariable.Timeout)

CustomKeywords.‘com.general.Click.clickUsingJS’(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/GST_Not_Available’),
GlobalVariable.Timeout)

CustomKeywords.‘com.general.Click.clickUsingJS’(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Parent_Product_Look_Up’),
GlobalVariable.Timeout)

WebUI.switchToWindowIndex(1)

WebUI.waitForPageLoad(GlobalVariable.Timeout)

WebUI.click(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/InstaCC_Parent_Product_LookUp_Result’))

WebUI.switchToDefaultContent()

WebUI.delay(3)

CustomKeywords.‘com.general.Click.clickUsingJS’(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/City_LookUp’), GlobalVariable.Timeout)

WebUI.switchToWindowIndex(1)

WebUI.waitForPageLoad(GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/City_LookUp_Search_TextBox’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
4, 7))

WebUI.click(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/City_LookUp_Go_Button’))

WebUI.click(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/City_LookUp_Result_Site1’))

WebUI.switchToDefaultContent()

WebUI.waitForElementNotVisible(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Loading_Indicator_Block’), GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Address_Line1’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
5, 7))

WebUI.focus(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Pin’))

WebUI.delay(1)

WebUI.waitForElementNotVisible(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Loading_Indicator_Block’), GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Pin’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
6, 7))

WebUI.focus(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Technical_Contact_Name’))

WebUI.delay(1)

WebUI.waitForElementNotVisible(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Loading_Indicator_Block’), GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Technical_Contact_Name’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
7, 7))

WebUI.delay(1)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Technical_Contact_Email’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
8, 7))

WebUI.delay(1)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Technical_Contact_Phone_No’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
9, 7))

WebUI.delay(1)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Implementation_Charge_InstaCC’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
10, 7))

CustomKeywords.‘com.general.Click.clickUsingJS’(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Supervisor_License_Checkbox’),
GlobalVariable.Timeout)

WebUI.waitForElementClickable(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Supervisor_Licenses_Unit_Price’),
GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Supervisor_Licenses_Unit_Price’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
12, 7))

WebUI.delay(1)

CustomKeywords.‘com.general.Click.clickUsingJS’(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/IVR_Port_Licenses_Checkbox’),
GlobalVariable.Timeout)

WebUI.waitForElementClickable(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/IVR_Port_Licenses_Unit_Price’), GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/IVR_Port_Licenses_Unit_Price’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
14, 7))

WebUI.delay(1)

CustomKeywords.‘com.general.Click.clickUsingJS’(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Chat_Licenses_Checkbox’),
GlobalVariable.Timeout)

WebUI.waitForElementClickable(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Chat_Licenses_Unit_Price’), GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Chat_Licenses_Unit_Price’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
16, 7))

WebUI.delay(1)

CustomKeywords.‘com.general.Click.clickUsingJS’(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Email_Licenses_Checkbox’),
GlobalVariable.Timeout)

WebUI.waitForElementClickable(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Email_Licenses_Unit_Price’), GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Email_Licenses_Unit_Price’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
18, 7))

WebUI.delay(1)

CustomKeywords.‘com.general.Click.clickUsingJS’(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Recording_Licenses_Checkbox’),
GlobalVariable.Timeout)

WebUI.waitForElementClickable(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Recording_Licenses_Unit_Price’), GlobalVariable.Timeout)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Recording_Licenses_Unit_Price’), findTestData(‘BSSE/InstaCC_Test_Data’).getValue(
20, 7))

WebUI.delay(1)

WebUI.setText(findTestObject(‘SFDC/SFDC_Product_Bundle/InstaCC_Global/Recording_Liceses_One_Time_Unit_Price’), findTestData(
‘BSSE/InstaCC_Test_Data’).getValue(21, 7))

WebUI.delay(1)

WebUI.click(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/Finish_Button’))

WebUI.waitForPageLoad(GlobalVariable.Timeout)

WebUI.waitForElementVisible(findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/New_Product_Configuration_Button’), GlobalVariable.Timeout)

I don’t see any evidence that you close the windows you are opening. This may not be an issue depending on your application.

Which call is causing the problem? This one? …

CustomKeywords.‘com.general.Click.clickUsingJS’(
  findTestObject(‘SFDC/SFDC_Product_Bundle/Common_PB/City_LookUp’), 
  GlobalVariable.Timeout)

How many windows are open at the same time? Window indexing can become tricky if you are not managing them correctly. Here are two links that might help:

And make sure you pay attention to this:

  • Window index is counted by order of window’s appearance and starts from 0. After closing a window, all windows appeared after that window will have index decreased by 1.
  • For example: we have 4 windows (index: 0, 1, 2, 3); close window index 1, after closing, the window with old index 2 will become new index 1, the window with old index 3 will become new index 2.
  • If users close current window, system will switch to the first window. If current window happens to be the first window, system will switch to the new first window. However we strongly recommend users switch to another window before closing current window to prevent any confusion.

Hi Russ,

All my test cases are blocked due to this issue. Can you please expedite if possible…!

Thank you.

Hi Rajesh

I can assure you, there are many, many people using WebUI.switchToWindowIndex() quite successfully. If there was a bug, it would have been reported by many, many people. So at this stage, there is no bug established.

For the reasons already mentioned, there is nothing to expedite. Moreover…

I spent time trying to help you but my questions have gone unanswered. If you want to expedite a solution, expedite your response accordingly.

Just for the record. I’m getting such an error too. The script does close the browser window that was opened by clicking on a button in the original window but the original window is still on the screen and after clicking another button on the original window:

“com.kms.katalon.core.exception.StepErrorException: [Custom Keyword Error] : Fail to click on element : com.kms.katalon.core.exception.StepErrorException: [Custom Keyword Error] : org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found”

In case of using WebUI.click instead of using the Custom Keyword that uses JS, the problem still exists:

(Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object *********’)
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:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
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 TempTestCase1596467319791.run(TempTestCase1596467319791.groovy:25)
Caused by: org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=84.0.4147.105)

Might I suggest you have confused your windows (handles, indexes, titles, whatever). If Selenium thinks the window was already closed, it is 99.99% guaranteed it was.

Post your code - all the relevant parts - and we’ll take a look.

Hi Russ. Like I wrote before, the script does close the browser window (I can see that it’s closed) that was opened by clicking on a button in the original window but the original window is still on the screen (I can see that it’s still on the screen) and after trying to click on another button on the original window (that is still on the screen), I’m seeing the error posted above.

Below is the function that handles the windows and after calling which the script is trying to click another button in the original window (that’s still on the screen)

public static boolean ChromeAgreementDownload(String filePathname) {

	boolean fileSuccessfullyDownloaded = false

	String url = WebUI.getUrl()

	int index = WebUI.getWindowIndex()

	WebUI.switchToWindowIndex(index + 1)

	String frameUrl = WebUI.getUrl()

	boolean isSpinnerVisibleWithinTimeout = WebUI.waitForElementVisible(findTestObject('Agreement/spinner__text'),
			GlobalVariable.ShortTimeout)

	if (isSpinnerVisibleWithinTimeout) {
		isSpinnerVisibleWithinTimeout = !(WebUI.waitForElementNotVisible(findTestObject('Agreement/spinner__text'),
				GlobalVariable.Default_Wait))
	}

	if (!(isSpinnerVisibleWithinTimeout)) {
		frameUrl += '/show_preview'

		WebUI.navigateToUrl(frameUrl)
		WebUI.waitForPageLoad(GlobalVariable.ShortTimeout)
		fileSuccessfullyDownloaded = ChromeCtrlSDownload(filePathname)
	}

	**WebUI.switchToWindowUrl(url)**

	WebUI.closeWindowUrl(frameUrl)

	return fileSuccessfullyDownloaded
}

And where is the code that switches back to the original window?

WebUI.switchToWindowUrl(url) (I was trying to make it Bold but it doesn’t seem to be working) :

public static boolean ChromeAgreementDownload(String filePathname) {

boolean fileSuccessfullyDownloaded = false

    // getting the URL of *the original window*
**String url = WebUI.getUrl()**

int index = WebUI.getWindowIndex()

WebUI.switchToWindowIndex(index + 1)

String frameUrl = WebUI.getUrl()

boolean isSpinnerVisibleWithinTimeout = WebUI.waitForElementVisible(findTestObject('Agreement/spinner__text'),
		GlobalVariable.ShortTimeout)

if (isSpinnerVisibleWithinTimeout) {
	isSpinnerVisibleWithinTimeout = !(WebUI.waitForElementNotVisible(findTestObject('Agreement/spinner__text'),
			GlobalVariable.Default_Wait))
}

if (!(isSpinnerVisibleWithinTimeout)) {
	frameUrl += '/show_preview'

	WebUI.navigateToUrl(frameUrl)
	WebUI.waitForPageLoad(GlobalVariable.ShortTimeout)
	fileSuccessfullyDownloaded = ChromeCtrlSDownload(filePathname)
}

    //  getting  back to *the original window*
**WebUI.switchToWindowUrl(url)**

WebUI.closeWindowUrl(frameUrl)

return fileSuccessfullyDownloaded

}

You seem to be using a mixture of WebUI.switchToWindowIndex and WebUI.switchToWindowUrl - my guess is, you’ve confused yourself as to which is which.

If I were you, I would stick to one or the other - I’d probably go with window index(es).

I’m doing it because I don’t know the URL of the window that is opened by clicking on a button in the original window. So, I have to use the index to switch to it. I don’t like working with index(es) though. I prefer using something more concrete, like URLs. I don’t remember seeing any restrictions on using a mixture of WebUI.switchToWindowIndex and WebUI.switchToWindowUrl in Katalon. Are there such restrictions?

No, only human fallibility. Whichever you choose, be sure you track each open/close meticulously. Either way, stick to one API to save you from yourself.

Thank you, Russ. I’ve tried using index(es) only and got the same errors. When I try closing the second window first and then switching to the original window ( which is quite the opposite of what is recommended at https://docs.katalon.com/katalon-studio/docs/webui-close-window-url.html#description- and https://docs.katalon.com/katalon-studio/docs/webui-close-window-index.html ), it seems to be working regardless of what is used (URLs or index(es) or a mixture of those).

Are you saying it’s working now?

Yes, it’ s working WHEN I try closing the second window first and then switching to the original window ( which is quite the opposite of what is recommended at https://docs.katalon.com/katalon-studio/docs/webui-close-window-url.html#description- and https://docs.katalon.com/katalon-studio/docs/webui-close-window-index.html )

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.