Dynamic variables/functions

Hi all. I have a task to trigger an action based on the contents of a table on a page - it’s a bunch of code that needs to move through each row. Each row has a checkbox that needs to be checked - a snippet of code run - then uncheck that box and move to the next row. The code calls a new window, does some actions, then closes the window and returns to the main previous window & then is called when the code progresses to the next row.

I’ve been trying out various suggestions that I’ve found on these forums and out on the wider interwebs - using Studio v 7.1.1 with Chrome and Firefox drivers.
I can extract the row number and have a for loop based on that.
The main code snippet is as follows:

for (int row = 0; row < rows_count; row++) {
    'Log number of row'
    log.logInfo('Value of row is ' + row)

    'set row ID'
    String dynamicID = row

    'build xpath'
    String xpath = ('sub-estate-selection-checkbox-' + dynamicID)

    'Log xpath statement'
    log.logInfo('Value of xpath is ' + xpath)

	'Detail on this solution from: https://medium.com/katalon-studio/handling-static-and-dynamic-test-objects-f49d04667e9d'

	'Create Dynamic object'
	String myxpath = String.format(MySelectors.dynamicIdPath,xpath)
	
	log.logInfo('Dynamic ID path is ' + myxpath)
	log.logInfo('value back from function is ' + MySelectors.getMyTestObject("xpath", myxpath))
	
    'click it'
    WebUI.click(MySelectors.getMyTestObject("xpath", myxpath))

And MYselectors is (after the import declarations):

public class MySelectors {
	public static final String dynamicIdPath = "//input[@id='%s']"

	public static TestObject getMyTestObject(String selectorType, String selectorValue) {
		TestObject to = new TestObject()
		to.addProperty(selectorType, ConditionType.EQUALS , selectorValue)
		return to
	}
}

The issue I’m finding at the moment is that it runs fine first time, but second time it fails. The success message for the WebUI.click line where the myselectors.getmytestobject is this on the first run:
click(MySelectors.getMyTestObject(“xpath”, myxpath))

Elapsed time: 0.531s

Object: '' is clicked on

Whereas on the second I get
Unable to click on object ‘’
….
Caused by: org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=79.0.3945.130)

I can see through my logevents that the for loop is working properly & creating the right xpath, however it’s not for actually executing it. Anyone spot any glaring errors in what I’m doing?
Cheers!
Ash

1 Like

Sounds like you tried to manipulate the popup window after it was closed - but you probably knew that.

I don’t see the switchToWindow code - perhaps share that too?

(BTW, great post - exemplary).

To elaborate more on @Russ_Thomas’s question, I think you would need to also share this portion of the code along with the for loop for more context.

Fair point! Here’s the full code after the declarations and firing of the initial page. Have redacted site details, hopefully I’ve not pulled out anything important. The initial page is index0, the spawned page is index 1. The log entries certainly imply everything is fine … until the second pass, where I do get an xml object being created within the myselectors code as //input[@id=‘sub-estate-selection-checkbox-1’] but I just can’t get the main code to click it!
Cheers in advance.

'Load the subestate table'
WebElement Table = driver.findElement(By.xpath('//table/tbody'))

'Split rows out based on tr tag'
List<WebElement> rows_table = Table.findElements(By.tagName('tr'))

KeywordLogger log = new KeywordLogger()

'Get count of table rows'
int rows_count = rows_table.size()

'Loop through the rows in the Sub-estate table'
for (int row = 0; row < rows_count; row++) {
    'Log number of row'
    log.logInfo('Value of row is ' + row)

    'set row ID'
    String dynamicID = row

    'build xpath'
    String xpath = ('sub-estate-selection-checkbox-' + dynamicID)

    'Log xpath statement'
    log.logInfo('Value of xpath is ' + xpath)

	'Detail on this solution from: https://medium.com/katalon-studio/handling-static-and-dynamic-test-objects-f49d04667e9d'
	
	
	'Create Dynamic object'
	String myxpath = String.format(MySelectors.dynamicIdPath,xpath)
	
	log.logInfo('Dynamic ID path is ' + myxpath)
	log.logInfo('value back from function is ' +  MySelectors.getMyTestObject("xpath", myxpath))
	
    'click it'

    WebUI.click(MySelectors.getMyTestObject("xpath", myxpath))

    WebUI.click(findTestObject('Object Repository/REDACTED'))

    WebUI.switchToWindowIndex('1')
	
    WebUI.navigateToUrl('REDACTED')

    'Only action the below if a token is found with our standard phrasing'
    if (WebUI.verifyTextPresent('stuff', false)) {
        WebUI.click(findTestObject('REDACTED'))

        'Check to renew API token'
        WebUI.click(findTestObject('REDACTED'))

        'Confirm renewal'
        WebUI.click(findTestObject('REDACTED'))
    }
    
    'Switch back to main window'
    WebUI.switchToWindowIndex(0)
	WebUI.delay(5)
	WebUI.switchToDefaultContent()
	myindex = WebUI.getWindowIndex()
	log.logInfo('Current Window Index is ' + myindex)
	
	WebUI.switchToWindowTitle('REDACTED')
	
//	WebUI.navigateToUrl('REDACTED')
//	WebUI.delay(5)
//	WebUI.click(findTestObject(REDACTED))
//	WebUI.delay(5)
    'Close the sub-state just viewed'
    WebUI.closeWindowIndex(1)

}

Whilst (hopefully) waiting on an answer, am playing with seeing if I can get it to fire with javascript instead.

So you have popup windows AND iframes?

Ahhhh. wonder if that’s it. I can’t see any iframe tags within the main source, but there’s masses within the css on the page source.
Hmm. will run the Spy to see if I can get it identified as an iframe there.
–Update–
Nope, no iframes on that page. :frowning:

So why are you using WebUI.switchToDefaultContent() ?

I admit, I’m finding it hard to follow your intentions - screenshots of the page might help.

Same question here, what’s the rationale for this line ?

:slight_smile: The rationale is that I’ve been trying to crack this (on and off) for weeks now, trying lots of different techniques. Pretty new to KS, so there may well be stuff in there that’s erroneous I’m afraid. Will send a screenshot of what I’m trying to access

No problem,

Just fyi, the documentation states that you should this keyword when dealing with some frame elements:

If you:

Then I’d suggest remove that line, and observe what error would removing it cause.

image
Table is in this format, I can select the first checkbox, but not the second. When a checkbox is selected, additional buttons appear on the page that I then click. This opens a separate window - I do my required actions on that window, then switch back to index0, delete the index1, and then need to un-check the checkbox. I couldn’t get that working, so have taken to refreshing the page again (which clears the checkbox). The buttons that appear will not function if multiple checkboxes are checked. Wish I had the capacity to change the source page …. but I don’t!
Cheers.

SwitchToDefaultContext removed. Same error experienced:

Try to share the entire console log, it may be helpful to have different eyes over the content.

2020-01-29 15:15:28.045 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2020-01-29 15:15:28.063 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/Renew API Certs
2020-01-29 15:15:29.691 DEBUG testcase.Renew API Certs                 - 1: openBrowser("")
2020-01-29 15:15:30.030 INFO  c.k.k.core.webui.driver.DriverFactory    - Starting 'Chrome' driver
2020-01-29 15:15:30.094 INFO  c.k.k.core.webui.driver.DriverFactory    - Action delay is set to 0 seconds
Jan 29, 2020 3:15:30 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 17566
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Jan 29, 2020 3:15:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
2020-01-29 15:15:33.950 INFO  c.k.k.core.webui.driver.DriverFactory    - sessionId = e5429870479166afdbc4de8c15a0a942
2020-01-29 15:15:33.985 INFO  c.k.k.core.webui.driver.DriverFactory    - browser = Chrome 79.0.3945.130
2020-01-29 15:15:33.986 INFO  c.k.k.core.webui.driver.DriverFactory    - platform = Windows Server 2012 R2
2020-01-29 15:15:33.987 INFO  c.k.k.core.webui.driver.DriverFactory    - seleniumVersion = 3.141.59
2020-01-29 15:15:33.987 INFO  c.k.k.core.webui.driver.DriverFactory    - proxyInformation = ProxyInformation{proxyOption=NO_PROXY, proxyServerType=HTTP, password=, proxyServerAddress=, proxyServerPort=0}
2020-01-29 15:15:34.034 DEBUG testcase.Renew API Certs                 - 2: driver = getWebDriver()
2020-01-29 15:15:34.122 DEBUG testcase.Renew API Certs                 - 3: navigateToUrl("xxxxxxx")
2020-01-29 15:15:45.049 DEBUG testcase.Renew API Certs                 - 4: setText(findTestObject("REDCACTED/input_Email Address_username (3)"), "xxxxxk")
2020-01-29 15:15:46.502 DEBUG testcase.Renew API Certs                 - 5: setEncryptedText(findTestObject("REDCACTED/input_Password_password (3)"), "xxxx")
2020-01-29 15:15:47.349 DEBUG testcase.Renew API Certs                 - 6: click(findTestObject("REDCACTED/button_Sign In"))
2020-01-29 15:15:47.982 DEBUG testcase.Renew API Certs                 - 7: click(findTestObject("REDCACTED/form_SECURITY CODE"))
2020-01-29 15:15:48.985 DEBUG testcase.Renew API Certs                 - 8: setText(findTestObject("REDCACTED/input_SECURITY CODE_code (1)"), "286726")
2020-01-29 15:15:49.567 DEBUG testcase.Renew API Certs                 - 9: click(findTestObject("REDCACTED/button_Submit"))
2020-01-29 15:16:10.987 DEBUG testcase.Renew API Certs                 - 10: click(findTestObject("REDCACTED/span_Sub-Estates (2)"))
2020-01-29 15:16:13.861 ERROR c.k.k.c.w.keyword.builtin.ClickKeyword   - ❌ javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
  (Session info: chrome=79.0.3945.130)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'SOLUSDC', ip: '10.78.10.70', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_181'
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: C:\Users\ADMINI~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:56385}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: e5429870479166afdbc4de8c15a0a942
2020-01-29 15:16:18.320 DEBUG testcase.Renew API Certs                 - 11: Table = driver.findElement(By.xpath("//table/tbody"))
2020-01-29 15:16:22.179 DEBUG testcase.Renew API Certs                 - 12: rows_table = Table.findElements(By.tagName("tr"))
2020-01-29 15:16:22.506 DEBUG testcase.Renew API Certs                 - 13: log = new com.kms.katalon.core.logging.KeywordLogger()
2020-01-29 15:16:22.509 DEBUG testcase.Renew API Certs                 - 14: rows_count = rows_table.size()
2020-01-29 15:16:22.508 WARN  c.k.katalon.core.logging.KeywordLogger   - Please use "KeywordUtil.logInfo()" instead of "new KeywordLogger()" constructor. "KeywordLogger" is an internal API and might be changed in the future.
2020-01-29 15:16:22.519 DEBUG testcase.Renew API Certs                 - 15: for ([row = 0, row < rows_count, (row++)])
2020-01-29 15:16:22.520 DEBUG testcase.Renew API Certs                 - 1: log.logInfo("Value of row is " + row)
2020-01-29 15:16:22.520 INFO  c.k.katalon.core.logging.KeywordLogger   - Value of row is 0
2020-01-29 15:16:22.520 DEBUG testcase.Renew API Certs                 - 2: dynamicID = row
2020-01-29 15:16:22.525 DEBUG testcase.Renew API Certs                 - 3: xpath = "sub-estate-selection-checkbox-" + dynamicID
2020-01-29 15:16:22.527 DEBUG testcase.Renew API Certs                 - 4: log.logInfo("Value of xpath is " + xpath)
2020-01-29 15:16:22.528 INFO  c.k.katalon.core.logging.KeywordLogger   - Value of xpath is sub-estate-selection-checkbox-0
2020-01-29 15:16:22.528 DEBUG testcase.Renew API Certs                 - 5: "Detail on this solution from: https://medium.com/katalon-studio/handling-static-and-dynamic-test-objects-f49d04667e9d"
2020-01-29 15:16:22.529 DEBUG testcase.Renew API Certs                 - 6: myxpath = String.format(dynamicIdPath, xpath)
2020-01-29 15:16:22.536 DEBUG testcase.Renew API Certs                 - 7: log.logInfo("Dynamic ID path is " + myxpath)
2020-01-29 15:16:22.537 INFO  c.k.katalon.core.logging.KeywordLogger   - Dynamic ID path is //input[@id='sub-estate-selection-checkbox-0']
2020-01-29 15:16:22.538 DEBUG testcase.Renew API Certs                 - 8: log.logInfo("value back from function is " + MySelectors.getMyTestObject("xpath", myxpath))
2020-01-29 15:16:22.554 INFO  c.k.katalon.core.logging.KeywordLogger   - value back from function is TestObject - ''
2020-01-29 15:16:22.555 DEBUG testcase.Renew API Certs                 - 9: click(MySelectors.getMyTestObject("xpath", myxpath))
2020-01-29 15:16:23.151 DEBUG testcase.Renew API Certs                 - 10: click(findTestObject("REDCACTED/button_Launch REDCACTED A (2)"))
2020-01-29 15:16:24.095 DEBUG testcase.Renew API Certs                 - 11: switchToWindowIndex("1")
2020-01-29 15:16:24.179 DEBUG testcase.Renew API Certs                 - 12: navigateToUrl("https://central.sophos.com/manage/config/settings/token-management")
2020-01-29 15:16:53.787 DEBUG testcase.Renew API Certs                 - 13: if (verifyTextPresent("BTLS Key for event monitoring", false))
2020-01-29 15:16:57.814 DEBUG testcase.Renew API Certs                 - 1: click(findTestObject("Page_REDCACTED/span_BTLS Key for event monitoring"))
2020-01-29 15:16:58.721 DEBUG testcase.Renew API Certs                 - 2: click(findTestObject("Page_REDCACTED/span_Renew"))
2020-01-29 15:16:59.610 DEBUG testcase.Renew API Certs                 - 3: click(findTestObject("Page_REDCACTED/button_Renew"))
2020-01-29 15:17:00.237 DEBUG testcase.Renew API Certs                 - 14: switchToWindowIndex(0)
2020-01-29 15:17:00.286 DEBUG testcase.Renew API Certs                 - 15: delay(5)
2020-01-29 15:17:05.322 DEBUG testcase.Renew API Certs                 - 16: myindex = getWindowIndex()
2020-01-29 15:17:05.365 DEBUG testcase.Renew API Certs                 - 17: log.logInfo("Current Window Index is " + myindex)
2020-01-29 15:17:05.367 INFO  c.k.katalon.core.logging.KeywordLogger   - Current Window Index is 0
2020-01-29 15:17:05.368 DEBUG testcase.Renew API Certs                 - 18: switchToWindowTitle("REDCACTED")
2020-01-29 15:17:05.431 DEBUG testcase.Renew API Certs                 - 19: closeWindowIndex(1)
2020-01-29 15:17:05.594 DEBUG testcase.Renew API Certs                 - 1: log.logInfo("Value of row is " + row)
2020-01-29 15:17:05.595 INFO  c.k.katalon.core.logging.KeywordLogger   - Value of row is 1
2020-01-29 15:17:05.595 DEBUG testcase.Renew API Certs                 - 2: dynamicID = row
2020-01-29 15:17:05.596 DEBUG testcase.Renew API Certs                 - 3: xpath = "sub-estate-selection-checkbox-" + dynamicID
2020-01-29 15:17:05.597 DEBUG testcase.Renew API Certs                 - 4: log.logInfo("Value of xpath is " + xpath)
2020-01-29 15:17:05.598 INFO  c.k.katalon.core.logging.KeywordLogger   - Value of xpath is sub-estate-selection-checkbox-1
2020-01-29 15:17:05.598 DEBUG testcase.Renew API Certs                 - 5: "Detail on this solution from: https://medium.com/katalon-studio/handling-static-and-dynamic-test-objects-f49d04667e9d"
2020-01-29 15:17:05.599 DEBUG testcase.Renew API Certs                 - 6: myxpath = String.format(dynamicIdPath, xpath)
2020-01-29 15:17:05.600 DEBUG testcase.Renew API Certs                 - 7: log.logInfo("Dynamic ID path is " + myxpath)
2020-01-29 15:17:05.603 INFO  c.k.katalon.core.logging.KeywordLogger   - Dynamic ID path is //input[@id='sub-estate-selection-checkbox-1']
2020-01-29 15:17:05.605 DEBUG testcase.Renew API Certs                 - 8: log.logInfo("value back from function is " + MySelectors.getMyTestObject("xpath", myxpath))
2020-01-29 15:17:05.607 INFO  c.k.katalon.core.logging.KeywordLogger   - value back from function is TestObject - ''
2020-01-29 15:17:05.608 DEBUG testcase.Renew API Certs                 - 9: click(MySelectors.getMyTestObject("xpath", myxpath))
2020-01-29 15:17:05.675 WARN  c.k.k.c.w.h.s.WebUIScreenCaptor          - Cannot take screenshot
2020-01-29 15:17:05.681 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Unable to click on object '' (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to click on object ''
	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.ClickKeyword.click(ClickKeyword.groovy:103)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:43)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$3.call(Unknown Source)
	at Renew API Certs.run(Renew API Certs:88)
	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 TempTestCase1580310924279.run(TempTestCase1580310924279.groovy:23)
Caused by: org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
  (Session info: chrome=79.0.3945.130)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'SOLUSDC', ip: '10.78.10.70', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_181'
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: C:\Users\ADMINI~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:56385}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: e5429870479166afdbc4de8c15a0a942
*** Element info: {Using=xpath, value=//input[@id='sub-estate-selection-checkbox-1']}
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
	at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:19)
	at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:353)
	at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:432)
	at org.openqa.selenium.By$ByXPath.findElements(By.java:348)
	at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:311)
	at org.openqa.selenium.support.events.EventFiringWebDriver.lambda$new$1(EventFiringWebDriver.java:105)
	at com.sun.proxy.$Proxy8.findElements(Unknown Source)
	at org.openqa.selenium.support.events.EventFiringWebDriver.findElements(EventFiringWebDriver.java:182)
	at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElements(WebUiCommonHelper.java:762)
	at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1109)
	at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
	at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:68)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.call(ClickKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:103)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:43)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$3.call(Unknown Source)
	at Script1575881129845.run(Script1575881129845.groovy:88)
	... 11 more
)
2020-01-29 15:17:05.694 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/Renew API Certs FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to click on object ''
	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.ClickKeyword.click(ClickKeyword.groovy:103)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:43)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$3.call(Unknown Source)
	at Renew API Certs.run(Renew API Certs:88)
	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 TempTestCase1580310924279.run(TempTestCase1580310924279.groovy:23)
Caused by: org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
  (Session info: chrome=79.0.3945.130)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'xxxxx', ip: '1.1.1.1.', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_181'
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: C:\Users\ADMINI~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:56385}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: e5429870479166afdbc4de8c15a0a942
*** Element info: {Using=xpath, value=//input[@id='sub-estate-selection-checkbox-1']}
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
	at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:19)
	at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:353)
	at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:432)
	at org.openqa.selenium.By$ByXPath.findElements(By.java:348)
	at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:311)
	at org.openqa.selenium.support.events.EventFiringWebDriver.lambda$new$1(EventFiringWebDriver.java:105)
	at com.sun.proxy.$Proxy8.findElements(Unknown Source)
	at org.openqa.selenium.support.events.EventFiringWebDriver.findElements(EventFiringWebDriver.java:182)
	at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElements(WebUiCommonHelper.java:762)
	at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1109)
	at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
	at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:68)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.call(ClickKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	... 17 more

2020-01-29 15:17:05.700 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/Renew API Certs

Okay, I’ll try my best.

This portion of the code:

- 9: click(MySelectors.getMyTestObject("xpath", myxpath))
2020-01-29 15:16:23.151 DEBUG testcase.Renew API Certs                 - 10: click(findTestObject("REDCACTED/button_Launch REDCACTED A (2)"))
2020-01-29 15:16:24.095 DEBUG testcase.Renew API Certs                 - 11: switchToWindowIndex("1")
2020-01-29 15:16:24.179 DEBUG testcase.Renew API Certs                 - 12: navigateToUrl("https://central.sophos.com/manage/config/settings/token-management")
2020-01-29 15:16:53.787 DEBUG testcase.Renew API Certs                 - 13: if (verifyTextPresent("BTLS Key for event monitoring", false))
2020-01-29 15:16:57.814 DEBUG testcase.Renew API Certs                 - 1: click(findTestObject("Page_REDCACTED/span_BTLS Key for event monitoring"))
2020-01-29 15:16:58.721 DEBUG testcase.Renew API Certs                 - 2: click(findTestObject("Page_REDCACTED/span_Renew"))
2020-01-29 15:16:59.610 DEBUG testcase.Renew API Certs                 - 3: click(findTestObject("Page_REDCACTED/button_Renew"))
2020-01-29 15:17:00.237 DEBUG testcase.Renew API Certs                 - 14: switchToWindowIndex(0)

Essentially you go to a new window, do some stuffs and then return back to the original window. Then:


2020-01-29 15:17:05.365 DEBUG testcase.Renew API Certs                 - 17: log.logInfo("Current Window Index is " + myindex)
2020-01-29 15:17:05.367 INFO  c.k.katalon.core.logging.KeywordLogger   - Current Window Index is 0
2020-01-29 15:17:05.368 DEBUG testcase.Renew API Certs                 - 18: switchToWindowTitle("REDCACTED")
2020-01-29 15:17:05.431 DEBUG testcase.Renew API Certs                 - 19: closeWindowIndex(1)
2020-01-29 15:17:05.594 DEBUG testcase.Renew API Certs                 - 1: log.logInfo("Value of row is " + row)

You are adding an extra switchToWindowTitle("REDACTED"), however the preceding code already results the browser to be at the original window (window at index 0 is window with REDACTED url right?). I suspect this extra switching causes the problem. You can try to check first if you are on a different window from REDACTED, and only switch if you’re not. So instead of using switchToWindowTitle("REDACTED"), you can check beforehand, like this:

String title = WebUI.getWindowTitle()
if(!REDACTED.equals(title)) {
    WebUI.switchToWindowTitle("REDACTED")
}

Please try and let me know if that helps.

nope, same error unfortunately.
Am I right in thinking that the error I should be focusing on is the “no such window: target window already closed”? Am wondering if it’s struggling returning the focus to the windowIndex(0) in some way.
Many thanks for the help on this btw. :slight_smile:

Ash, take a step back and do this…

  1. Perform the operations by hand.
  2. Write down in plain English all the steps you take.
  3. Convert the English to pseudo code.

Lastly, obviously,

  1. Make sure your groovy code is implementing the pseudo code.

Come back and ask here if you have trouble between #3 and #4.

I’m convinced you know what you’re trying to achieve. It’s a bit of a challenge for us to see where you might be tripping yourself up. Follow those steps and you MAY just solve it yourself. You certainly wouldn’t have written code about iframes had you followed those steps, right?

Can you elaborate on this line ? Does REDACTED window mean the original window (index = 0) ?

By the way I agree with @Russ_Thomas, the current state of your errors is mixed between the fundamental logical error and errors that are introduced by your trying different methods at the same time. You should try to write the essential logic down as pseudo-code and implement it accordingly.

Also, a line stands out to me:

navigateToUrl("https://central.sophos.com/manage/config/settings/token-management")

This appears out of nowhere, I am not sure this is what the user would do, would you navigate to this URL directly as an end-user ?

1 Like

Hi @Russ_Thomas, will give it a stab. I’m definitely not a Java coder, and ‘think’ I have the groovy right, but I have been recklessly nicking code from the interwebs to help here. :innocent:

You need two things to create a patchwork quilt:

  1. Bunch of good patches.
  2. Needle and thread.

Other people give you the patches. You provide the needle and thread.

Get it? :slight_smile: