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


#1

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)


#2

Can you post the code from the Test Case?


#3

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)


#4

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.

#5

Hi Russ,

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

Thank you.


#6

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.