WebUI.executeJavaScript() alert in Safari

Hi - we have a custom keyword that uploads some data to our UAT. While the data is uploading, I have a javascript ‘alert’ come up that says “stand by…” more or less. Then I call WebUI.acceptAlert() to clear the alert. This all works well, except in Safari. WebUI.acceptAlert() simply doesn’t work for me in this case. Below is my code to both set, then clear the js alert.

Create alert:
WebUI.executeJavaScript("alert('Uploading file ' + arguments[1] + ' to imaging session ' + arguments[0] + ' ...please stand by.')", Arrays.asList(SESSION_LABEL, FILE_NAME))

Remove alert:
WebUI.acceptAlert()

Any help is appreciated.

Patrick - what error do you receive?

Does the acceptAlert() execute and timeout?

Yes, just times out. No error, no failure. The js alert remains open in the browser window too.

I’d like to see that error - please copy-paste it here.

A screen shot of the page at that point would be nice, too.

COnsole output here:

2019-04-02 15:12:54.586 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/Validation Test Cases/S1026 - DICOM Anonymization/T1026.5_v1 - Add Scan to Existing Session - Sitewide and Project-Level Anonymization FAILED.

Reason:

com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.

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.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$17.call(Unknown Source)

at com.radiologics.automation_utilities.Upload.uploadSessionDataArchive(Upload.groovy:67)

at com.radiologics.automation_utilities.Upload.invokeMethod(Upload.groovy)

at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)

at T1026.5_v1 - Add Scan to Existing Session - Sitewide and Project-Level Anonymization.run(T1026.5_v1 - Add Scan to Existing Session - Sitewide and Project-Level Anonymization:90)

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:331)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)

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 TempTestCase1554235756522.run(TempTestCase1554235756522.groovy:21)

Caused by: org.openqa.selenium.UnhandledAlertException: : 

Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'

System info: host: 'pscloughbookpro.lan', ip: 'fe80:0:0:0:1411:8be4:799c:9aa9%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.3', java.version: '1.8.0_181'

Driver info: com.kms.katalon.selenium.driver.CSafariDriver

Capabilities {acceptInsecureCerts: false, browserName: Safari, browserVersion: 12.0.3, javascriptEnabled: true, platform: MAC, platformName: MAC, setWindowRect: true}

Session ID: 557687BC-5E53-4A7E-BE66-6D4352434CF8

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)

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.CSafariDriver.execute(CSafariDriver.java:21)

at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:536)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.doCall(ExecuteJavascriptKeyword.groovy:48)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.call(ExecuteJavascriptKeyword.groovy)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$17.call(Unknown Source)

at com.radiologics.automation_utilities.Upload.uploadSessionDataArchive(Upload.groovy:67)

at com.radiologics.automation_utilities.Upload.invokeMethod(Upload.groovy)

at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)

at Script1553612780548.run(Script1553612780548.groovy:90)

... 11 more

I am setting (and trying to accept) this alert within a custom keyword that uploads data. Not sure if that is worth mentioning or not. This keyword works perfectly with other browsers. I could forgo the alert if the browser==safari, but I’d like to have it if possible.

Here is a screenshot of my js alert that I produce and am attempting to close.

That’s not an alert.

You just need to click on that Close link (or button, or whateverthehell it is).

I had that thought too. But the code that creates this modal is:

WebUI.executeJavaScript("alert('Uploading file ' + arguments[1] + ' to imaging session ' + arguments[0] + ' ...please stand by.')", Arrays.asList(SESSION_LABEL, FILE_NAME))

It’s possible to hijack the browser’s alert and use your own. But let’s not get into the weeds here…

Right click on that Close thing, choose “Inspect” and post a screen shot of the devtools HTML you find.

Will do. Just for visual proof, here is what the same js “alert” looks like in Chrome:

image

So I’ll need to do some logic to say if browser==safari, click the close btn.

Oh… my bad… not familiar with Safari. That sure doesn’t look like a regular browser alert/confirm/whatever.

You can probably forget the right-click - won’t work.

Patrick

I can’t be sure this will help, but…

I think the problem is actually on setting the alert. When running in debug, it hangs on this line of code. Never gets to the acceptAlert. The strange thing is that it visually produces the “alert” (as pictured above).

WebUI.executeJavaScript(“alert(‘Hi!!’)”, null)

That might be a webdriver issue - it needs to switch the context to the alert window and perhaps Safari isn’t playing nicely.

But I’m only guessing here…

I cant even get that far. The code fails right as the js alert is produced. As a reminder, this is a SAFARI issue only.

Code below:

WebUI.executeJavaScript("alert('Hello world.')",null)

WebUI.switchToWindowIndex(1)

WebUI.acceptAlert()

WebUI.switchToDefaultContent()

Never makes it to line 2 above. When line 1 is run, I get the below exception:

2019-04-03 08:19:47.733 ERROR c.k.k.core.keyword.internal.KeywordMain - ❌ Unable to execute JavaScript. (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.

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.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$0.call(Unknown Source)

at New Test Case.run(New Test Case:37)

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:331)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)

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 TempTestCase1554297557038.run(TempTestCase1554297557038.groovy:21)

Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (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: 'Ps-CloughBookPro.local', ip: 'fe80:0:0:0:1411:8be4:799c:9aa9%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.3', java.version: '1.8.0_181'

Driver info: com.kms.katalon.selenium.driver.CRemoteWebDriver

Capabilities {applicationCacheEnabled: true, browserName: safari, cleanSession: true, cssSelectorsEnabled: true, databaseEnabled: true, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: false, nativeEvents: true, platform: MAC, platformName: MAC, rotatable: false, version: 13605.3.8, webStorageEnabled: true, webdriver.remote.sessionid: 3f2dc9b2fb24d3485e8bd5a5e8f...}

Session ID: 3f2dc9b2fb24d3485e8bd5a5e8f4653b8d70f9fb

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.RemoteWebDriver.execute(RemoteWebDriver.java:600)

at com.kms.katalon.selenium.driver.CRemoteWebDriver.execute(CRemoteWebDriver.java:31)

at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:536)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.doCall(ExecuteJavascriptKeyword.groovy:48)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.call(ExecuteJavascriptKeyword.groovy)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)

at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$0.call(Unknown Source)

at Script1553048048716.run(Script1553048048716.groovy:37)

... 11 more

)

And what does this do?

Same error. Never to gets to the acceptAlert(). Just fails upon rendering the alert.

image

2019-04-03 15:27:44.751 WARN  c.k.k.c.w.h.s.WebUIScreenCaptor          - Cannot take screenshot
2019-04-03 15:27:44.771 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Unable to execute JavaScript. (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
	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.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$0.call(Unknown Source)
	at New Test Case.run(New Test Case:37)
	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:331)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)
	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 TempTestCase1554323192063.run(TempTestCase1554323192063.groovy:21)
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (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: 'Ps-CloughBookPro.local', ip: 'fe80:0:0:0:4e6:291:dacc:40f2%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.3', java.version: '1.8.0_181'
Driver info: com.kms.katalon.selenium.driver.CRemoteWebDriver
Capabilities {applicationCacheEnabled: true, browserName: safari, cleanSession: true, cssSelectorsEnabled: true, databaseEnabled: true, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: false, nativeEvents: true, platform: MAC, platformName: MAC, rotatable: false, version: 13605.3.8, webStorageEnabled: true, webdriver.remote.sessionid: a1701e105a0cca47f8f305e7a74...}
Session ID: a1701e105a0cca47f8f305e7a743fd6e19486b23
	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.RemoteWebDriver.execute(RemoteWebDriver.java:600)
	at com.kms.katalon.selenium.driver.CRemoteWebDriver.execute(CRemoteWebDriver.java:31)
	at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:536)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.doCall(ExecuteJavascriptKeyword.groovy:48)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword$_executeJavascript_closure1.call(ExecuteJavascriptKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
	at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$0.call(Unknown Source)
	at Script1553048048716.run(Script1553048048716.groovy:37)
	... 11 more
)

@Patrick_Clough, I’m moving this to the Bugs category. In the meantime, try updating your safari webdriver.

@devalex88 There is something strange going on here. Please read the foregoing, then please consider my further points here…

The key error lines from Patrick’s dump seem to be:

And …

The first line seems to be the “new normal” if an alert is present and acceptAlert() has issues - but why? The latter message seems weird to me. I don’t have access to Safari so I can’t investigate further.

When I run this code (note WITHOUT an acceptAlert()

    WebUI.executeJavaScript('alert("Hello World")', null)

I see the alert then get these two lines:

Unable to execute JavaScript. (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript. ...

And then as you would expect…

Caused by: org.openqa.selenium.UnhandledAlertException: Dismissed user prompt dialog: Hello World: 

Can you explain why Katalon/Webdriver is responding with “Unable to execute JavaScript”? There is no Javascript beyond the call to alert() so what JavaScript is it unable to execute? :exploding_head:

I am now of the opinion that my assumptions about execution of JavaScript while the browser is “paused” on an alert maybe ill-founded. I’m not completely certain but I thought I had done that in the past and recently found it was not working. That is what caused me to write this tip:

When I wrote the tip I thought it made some sense that the browser couldn’t run more JavaScript… but that’s the same message here with one line of JS it certainly has run. :exploding_head:

If you can find out why this is happening and solve the safari issue at the same time I’ll make sure we sing your praises from rooftops all round the world :wink: