Switch to browser error

Hi,

I’m currently trying to to automate the following flow:

  1. open browser
  2. open pdf in browser
  3. Search for a string
  4. put the amount of times the specific string is found in a variable

To make things easier i’m using the following chrome plugin: https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm

When I open a chrome window with the built in ‘open website’ it opens a chrome window without all my extensions loaded in. To counter this I opened chrome using the ‘Launch Application’ action.

I am able to activate the search function, enter my string and get the amount of times it appears in the pdf. When I want to get the value by using a Web Element I can’t use the xPath selector. I tried to fix this by adding a switch to browser, but then I get the following error:

Error executing SwitchToBrowserAction com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=SwitchToBrowserAction.ftl,id=7,name=Optional[SwitchToBrowserAction],parent=-1,children=[8],arguments=ActionArguments[delay=[0],xsi:type=[recorder:SwitchToBrowserAction, recorder:SwitchToBrowserAction],pollingInterval=[300],active=[true],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:64) at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:152) at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Failed switch to browser. It might be closed in preceding actions. 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.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:258) at Script8.run(Script8.groovy:11) 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:65) 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:64) at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:152) 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.WebDriverException: Web driver has not been started yet. Please open a web page before. Command duration or timeout: 0 milliseconds Build info: version: '9.2.0.4', revision: '1a10eeeced', time: '2018-11-29T10:44:59.891Z' System info: host: 'PC00318', ip: '192.168.40.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121' Driver info: com.freedomoss.crowdcontrol.webharvest.selenium.wrapper.RemoteDriverWrapper Capabilities [{imageSimilarityThreshold=0.8, extra.executor.id={Name=RPA Recorder}, CLOSE_ALL_WINDOWS=false, browserName=universal, javascriptEnabled=true, extra.capabilities.context={"browserType":"universal","startInPrivate":false,"blockImages":false,"maximizeOnStartup":false,"customCapabilities":{"platform":"WINDOWS","javascriptEnabled":true,"SEARCH_ALL_WINDOWS":true,"CLOSE_ALL_WINDOWS":false,"imageSimilarityThreshold":"0.8"},"executorId":{"Name":"RPA Recorder"}}, platformName=WINDOWS, SEARCH_ALL_WINDOWS=true, platform=WINDOWS}] Session ID: 13e3ba47-e4df-4a95-af97-2a3cdf983440 *** Element info: {Using=tag name, value=html} 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.findElements(RemoteWebDriver.java:473) at org.openqa.selenium.remote.RemoteWebDriver.findElementsByTagName(RemoteWebDriver.java:520) at org.openqa.selenium.By$ByTagName.findElements(By.java:327) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:434) at com.workfusion.rpa.helpers.RPA.getElements(RPA.java:974) at com.workfusion.rpa.helpers.RPA.$$(RPA.java:932) 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 org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151) 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 Script8.run(Script8.groovy:9) 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:65) 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:64) at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.playNextAction(PlaybackLogic.java:152) at com.workfusion.studio.rpa.recorder.player.PlaybackLogic.run(PlaybackLogic.java:112) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Web driver has not been started yet. Please open a web page before. at com.workfusion.universal.state.UniversalDriverState.switchToWebDriver(UniversalDriverState.java:128) at com.workfusion.universal.state.UniversalDriverState.switchToDriverBySelector(UniversalDriverState.java:82) at com.workfusion.universal.driver.UniversalDriver.findElements(UniversalDriver.java:73) at org.openqa.selenium.remote.server.handler.FindElements.call(FindElements.java:50) at org.openqa.selenium.remote.server.handler.FindElements.call(FindElements.java:35) at org.openqa.selenium.remote.server.handler.WebDriverHandler.handle(WebDriverHandler.java:41) at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:133) at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:205) 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)

How could I counter this?

Hi @Thibaultmarrannes to use XPaths and switch to browser, you have to open the browser using Open website action. You cannot do it if you use Launch application for it.

To use the installed extension, you can open your existing profile in Chrome with the help of capabilities.
However, you can only use capabilities in a bot task.
So you need to create your recording, then export it to a Bot task and then add the capability to the code.

Hi ashapkina,

as usual, thank you for the quick response :).

I fixed it by installing the plugin every time the script runs. takes only 15 seconds and seemed like the easiest way to do this since I’m not really that fond/capable of working with bot tasks.

I have yet another question though.

Is it possible to append a string to a list?

EDIT: found it! you can use the expression action found under Variables.

Thank you !

1 Like

Yes, it is another way to do it :grinning: Glad you got it solved!