Hi,
I have an open browser activity which opens a url in the browser after that i want to open another url using custom script without closing the previous window.Is there anyway to open a url in new tab using custom script.
i have written this script to open url in new tab,it is working perfect except one error which is related to timeout,
@CustomScriptAction(
)
def customScript() {
executeJavaScript("window.open('https://www.google.com/', '_blank')");
}
Error executing CustomScriptAction
com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=CustomScriptAction.ftl,id=66,name=Optional[CustomScriptAction],parent=61,nextSibling=67,arguments=ActionArguments[delay=[0],timeoutMs=[10000],xsi:type=[recorder:CustomScriptAction, recorder:CustomScriptAction],pollingInterval=[300],active=[true],script=[@CustomScriptAction(
)
def customScript() {
executeJavaScript(“window.open(‘https://www.google.com/’, ‘_blank’)”);
}
],awaitTimeout=[5000]]]
at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:54)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.ScriptTimeoutException: Timed out after 0 ms
Build info: version: ‘9.4.0.3’, revision: ‘abf2ebe0f1’, time: ‘2019-05-29T13:21:06.482Z’
System info: host: ‘DPCD-HJJTH32’, ip: ‘172.16.3.151’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{moz:profile=C:\Users\aashu.singh\AppData\Local\Temp\rust_mozprofile.OzJu5cCYnxt6, rotatable=false, moz:geckodriverVersion=0.22.0, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss and notify, strictFileInteractability=false, moz:headless=false, platform=XP, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=false, browserVersion=68.0.2, moz:shutdownTimeout=60000, platformVersion=10.0, moz:processID=59952, browserName=firefox, moz:buildID=20190813150448, javascriptEnabled=true, platformName=XP, setWindowRect=true, moz:webdriverClick=true}]
Session ID: 5f496c8f-5d32-483e-8739-e078940a1023
Command duration or timeout: 0 milliseconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:41)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:741)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:677)
at com.workfusion.rpa.helpers.Script.executeJavaScript(Script.java:317)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:104)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:326)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:197)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:209)
at CustomScript_customScript.customScript(Script6.groovy:12)
at CustomScript_customScript$customScript.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at Script6.run(Script6.groovy)
at com.workfusion.studio.rpa.recorder.playback.shell.GroovyShellWrapper.executeScript(GroovyShellWrapper.java:48)
at com.workfusion.studio.rpa.recorder.playback.player.PlaybackContext.executeScript(PlaybackContext.java:108)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.executeBehavior(TemplateAction.java:33)
at com.workfusion.studio.rpa.recorder.playback.flow.StandardControlFlow.execute(StandardControlFlow.java:46)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:28)
at com.workfusion.studio.rpa.recorder.playback.action.template.TemplateAction.execute(TemplateAction.java:15)
at com.workfusion.studio.rpa.recorder.playback.player.ActionPlayer.next(ActionPlayer.java:81)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:154)
at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.ScriptTimeoutException: Timed out after 0 ms
Build info: version: ‘9.4.0.3’, revision: ‘abf2ebe0f1’, time: ‘2019-05-29T13:21:06.482Z’
System info: host: ‘DPCD-HJJTH32’, ip: ‘172.16.3.151’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{moz:profile=C:\Users\aashu.singh\AppData\Local\Temp\rust_mozprofile.OzJu5cCYnxt6, rotatable=false, moz:geckodriverVersion=0.22.0, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss and notify, strictFileInteractability=false, moz:headless=false, platform=XP, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=false, browserVersion=68.0.2, moz:shutdownTimeout=60000, platformVersion=10.0, moz:processID=59952, browserName=firefox, moz:buildID=20190813150448, javascriptEnabled=true, platformName=XP, setWindowRect=true, moz:webdriverClick=true}]
Session ID: 5f496c8f-5d32-483e-8739-e078940a1023
Build info: version: ‘9.4.0.4’, revision: ‘1fbe520b9b’, time: ‘2019-06-20T13:08:57.971Z’
System info: host: ‘DPCD-HJJTH32’, ip: ‘172.16.3.151’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: driver.version: UniversalDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:186)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:121)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:50)
at org.openqa.selenium.remote.server.ActiveSessionCommandExecutor.execute(ActiveSessionCommandExecutor.java:43)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:741)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:677)
at com.workfusion.universal.driver.UniversalDriver.executeScript(UniversalDriver.java:151)
at org.openqa.selenium.remote.server.handler.ExecuteScript.call(ExecuteScript.java:54)
at org.openqa.selenium.remote.server.handler.WebDriverHandler.handle(WebDriverHandler.java:41)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:134)
at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:206)
at org.openqa.selenium.remote.server.InMemorySession.execute(InMemorySession.java:98)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:231)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
You cannot use ExecuteJavaScript in a Custom Action.
You need to export the recording as a bot task and code in the Code perspective to use it.
can we open it using executeJavaScript(“window.open(‘https://www.google.com/’, ‘_blank’)”);
method inside custom script.it is working but giving timeout error,could you correct me what i am doing wrong.
Try increasing the timeout for actions in RPA Recorder Preferences.
Hi @aashu.singh ,
I’ve got a solution for you.
So after you open new tab with your custom script, you need to add one more custom script, so the robot switches to this tab as active. As it can’t capture the Xpath, because the bot thinks the page is still the same.
So just add this Custom script:
@CustomScriptAction(
)
def
customScript() {
switchToNextWindow()
}
After your custom script and you will be able to get the Xpath.
See the example below:
The first Custom action:
The second custom action:
Hi @iostapuk,
can you share the executeJavaScript code as it is not fully visible in the screenshot or if possible whole steps.
@aashu.singh It’s just the same as you posted above:
@CustomScriptAction(
)
def customScript() {
executeJavaScript(“window.open(‘https://www.google.com/’, ‘_blank’)”);
}
I’ve just changed the website url
@iostapuk thanks for the help.
It working fine now, it works if we put the custom script inside open browser activity.
one question here will it work in control tower or not?
Glad that it works. Yes, it should work fine. But please note that If you have more than one custom script in the recording, you need to define a different method for each action as described in our Knowledge Base - https://kb.workfusion.com/display/RPAe/Code+Samples
Please see what I mean based on my example:
The first script:
The second script:
thanks for the info