How to download files with a loop without stopping?

Hello
I am trying to create a bot that can download PDF file from a website to a specific directory on my PC. The program or bot is to be used only two times a year:

  1. June and
    2, December every year.

I managed to create the bot that accepts the following INPUT:

  1. USERNAME (variable)
  2. PASSWORD (variable)
  3. ONETIME_CODE (sms)

The bot identifies the files with Wait for Image function. The image is read into a variable which is used in a While Loop. But the stops after it fines only one file, it goes on to download and save the file on the directory.

How do I ask the loop to continue to identify the rest of files and save them on the same directory, without starting from scratch.

Best of Regards
O.Papsey

Do you have another Wait for image action at the end of the While Loop?
Can you share your recording?

Hello and thanks for quick responce
The following is my code:

  1. The loop in the code Works but it does not repeat itself.

  2. My OCR does not work, if though I think I did everything correct. The second Picture includes the OCR in the code. I always get the following error msg. Picture nr3: Last week I had different error msg. That the OCR I took does not exist. But I got the following in Picture 3 today.

  3. Tried to include the OCR in the WHILE LOOP but this did not work either.

I found out that my OCR was not STARTED. I started it, and ran the program again. But again I got the following error Message.

Looks like you need to update to a new RPA Express version with a new OCR license.

Can you post the screenshot with details of the Wait for Image action?

Hello
The two attachments are pictures of Wait for image action. The second one is the website directory where the loop is supposed to recognise and click and open [ TILSENDT SELANGIVELSE ].

I did som detail analysis of the program this morning. I found out that the word SELANGIVELSE in my Wait for image is also found in other rows. The loop identifies these rows but does not click the images at all.


Hello
My analyses was correct, it was the word SELANGIVELSE found in other rows that confused the program. After I changed the image to TILSENT, and run the program, it worked.

Please bear With me.
My program still has two bugs which I hope you can help me With.

  1. Mouse click action on download [PDF] fails always indicating Image not found. See picture
  2. Mouse click action work With only [Webelement Xpath] See Picture. This is not correct, simply because download PDF for all emails/documents have different XPATHS. I you can help me out here.

Thanks in advance

What image do you use for the mouse click?

Hello
The image for the mouse click is [Tilsendt]

It yields IMAGE NOT FOUND WebDriverException. This is the mouse click before clicking

My Wait for image function does work
My OCR does not work.

Yes I will post my Picture to the site.

Regards

You need to look for the image before the loop, and then again at the end of the loop.
So all actions that need to be repeated in the loop have to be nested inside it, including the 2nd Wait for image action.
Both Wait for image actions are the same.

In this case the bot will repeat all actions in the While loop while there is not image it looks for in Wait for image action on the screen.

The image on which the bot needs to click has to be unique. If there are several identical images on the screen, it can click on the wrong one or fail.
Make sure all images are unique and always look the same on the screen.

Thank you. Working on it.

1 Like

Hello and goodmorning
I have customized the sample code you send to me, and it works fine only With Xpath. But the Wait For Image function still does not work, even though the image is unigue. I tried it With OCR but again I get (Image not found) error msg.

I wounder if this has something to do with the the application it self. Because I have just installed the 2.2 Version of WorkFusion.

Best of Regards

Are you sure the image is visible on the screen at this time and is exactly the same as the image you use in the action?

Hello
The attached picture is the sample code.
Line discription: 22: Wait for Image (5000 ms) This image is unique. This time am only checking the Waith for image action. Not the Loop itself. The image TILSENDT is found on only one document, it is unique. But the program yields no image found error Message. This comes at line 26.

Home of Regards


You use condition: if “image_found” is “false”. So the loop starts only if the image is not found on the screen. So, if there is no such image, the bot cannot click on it.

Try recapturing the image you use in Wait for image and in the Mouse click action and changing the condition to true.

Also, the second Wait for image action is missing a variable.

Hello
I thought my Application of the OCR function was faulty. I captured a New image With OCR and read it in to a variable (test_tilsendt).
The mouse click opened the folder where I captured the OCR image. B I still get image not found error message.

Error executing OcrAction
  com.workfusion.studio.rpa.recorder.playback.PlaybackException: Error executing TemplateAction[templateName=OcrAction.ftl,id=20,name=Optional[OcrAction],parent=1,nextSibling=21,arguments=ActionArguments[varName=[text_tilsendt],imageName=[C:\\Users\\OPC\\workfusion-workspace\\rpae_project\\Logg inn altinn\\1550660269075-anchor-1550660269144.apng],fullImageName=[1550660269075.png],xsi:type=[recorder:OcrAction, recorder:OcrAction],pollingInterval=[300],active=[true],type=[CONTROL],offsetX=[182],offsetY=[-2],delay=[0],width=[237],comment=[Les ocr tekst i variable text_ocr],actionDetails=[(to 'text_tilsendt' rectangle 237 x 20)],height=[20],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: org.openqa.selenium.WebDriverException: Image not found : 1550660269075-anchor-1550660269144.apng
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: 'PC0Z4M4K', ip: '10.14.4.48', 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: 42f80bce-b591-4441-8750-04f8d31ba2b1
      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.ImageElement.findImageRectangle(ImageElement.java:184)
      at com.workfusion.rpa.helpers.ImageElement.getRect(ImageElement.java:86)
      at com.workfusion.rpa.helpers.UiElement.getRect(UiElement.java:1278)
      at org.openqa.selenium.WebElement$getRect$2.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 Script17.run(Script17.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.util.NoSuchElementException: Image not found : 1550660269075-anchor-1550660269144.apng
      at sun.reflect.GeneratedConstructorAccessor48.newInstance(Unknown Source)
      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.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
      at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
      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:250)
      at Script1$1.call(Script1.groovy:12)
      at Script1$1.call(Script1.groovy)
      at com.workfusion.common.utils.SynchUtils.withFocusLock(SynchUtils.java:47)
      at com.workfusion.common.utils.SynchUtils$withFocusLock.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:136)
      at Script1.run(Script1.groovy:5)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:444)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:482)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:453)
      at com.workfusion.autoit.driver.script.GroovyExecutor.execute(GroovyExecutor.java:45)
      at com.workfusion.autoit.driver.AutoItDriver.executeScriptInternal(AutoItDriver.java:235)
      at com.workfusion.autoit.driver.AutoItDriver.executeScript(AutoItDriver.java:190)
      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: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)

Please share the screenshot of the OCR action to see the capture and anchor regions, and the screenshot of the screen on which the bot needs to find these images.

Hello,
Attached is the OCR Action and the OCR Target location.

Thanks in advance
Omar

But how does the screen look at the time the bot has to perform OCR, does it contain the same image that is used as the anchor region in the OCR actions? If the image is opened on the screen in another resolution or some of the text is different on the screen and in the anchor region the bot will not be able to find this image.