Does anyone know how to interact with any about:blank windows in chrome? I cannot seem to get anything i have tried to work. All I am trying to do is let it open switch to and close it.
Hi there,
Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.
Thanks!
int currentWindowIndex = WebUI.getWindowIndex()
String script =
var handles = [];
var titles = [];
handles.push(window.name || window.location.href);
titles.push(document.title);
for (var i = 0; i < window.frames.length; i++) {
var frame = window.frames[i];
handles.push(frame.name || frame.location.href);
titles.push(frame.document.title);
}
JSON.stringify({ handles: handles, titles: titles });
def result = WebUI.executeJavaScript(script, null)
println("JavaScript result: " + result)
def jsonSlurper = new JsonSlurper()
def data = jsonSlurper.parseText(result)
println("Parsed data: " + data)
def windowHandles = data.handles
def windowTitles = data.titles
println("Window handles: " + windowHandles)
println("Window titles: " + windowTitles)
String targetTitle = 'about:blank'
int index = windowTitles.indexOf(targetTitle)
println("Index of target title: " + index)
if (index != -1) {
WebUI.switchToWindowIndex(index)
WebUI.takeScreenshot()
WebUI.closeWindowIndex(index)
WebUI.switchToWindowIndex(currentWindowIndex)
}
Hi @josh.meeks,
Can you try with this if the window has the title
// Wait for the about:blank window to open
WebUI.delay(2)
// Switch to the about:blank window
WebUI.switchToWindowTitle("about:blank")
// Close the about:blank window
WebUI.closeWindow()
or by index
WebUI.switchToWindowIndex(1) // Index starts from 0, so 1 is the second window
// Close the window
WebUI.closeWindow()
I have tried this as well as the index method you suggested. The issue is that there is a print dialog present atop the about:blank window, and either way I cant seem to get Katalon to interact with the window.
Using Robot VK does allow me to close the window but it only works occasionally. I have to manually interact with the window from time to time.
It seems that there is a timing issue with robot vk as well. If I let the window load then robot vk will not close the window, but if I run the keys before the window load has finished it seems to close the window no problem.
hi @josh.meeks
the about:blank window is reachable, the print dialog on top of it is not. it is a native chrome dialog, not a web window, so switchToWindow gets you to the page underneath but every command then blocks until the dialog goes away, which is why robot escape only works when it fires before the dialog finished opening.
what has worked for me is not letting the dialog appear. stub print before the click that opens it:
WebUI.executeJavaScript("window.__printed = false; window.print = function(){ window.__printed = true }", null)
WebUI.click(findTestObject('Page/btn_Print'))
if the print is triggered inside the about:blank popup itself (the page writes content into it and calls print), stub it there after switching: switchToWindowIndex(1), run the same executeJavaScript, then closeWindow. the popup usually calls print after a short delay, so do the switch straight after the click.
if you need chrome to actually print, add --kiosk-printing to the chrome args in Desired Capabilities, it prints silently to the default printer and never shows the dialog. set the default printer to pdf on the test machine.