To fix an error

Asked by swethaa

Hi all .have a script that open a set of PDF's one by one in a loop and looks for set of images (that are again traversed in a loop one after another..inner loop) and when a match is found the text to the right of match is extracted..Im having ann error.Pls help me.
Script:
import os
def close():
        switchApp("taskmgr.exe")
        click( )
        click( )
        click( )

App.open("taskmgr.exe")
click( )
type("CC:\\Users\\268263\\Desktop\\download files_life insurance\\pdf\\")
click( )
click( )
App.close("taskmgr.exe")
u = list(findAll(pdficon )) **PDF where an image is looked"
for u1 in u:
   doubleClick(u1)
   addImagePath("CC:\\Users\\268263\\Desktop\\download files_life insurance\\images\\")
   imgPath=list(getImagePath())
   for v1 in imgPath:
       if find(v1): **v1 is image searched in u1 PDF **
         m=find(v1).right().text()
       else:
         popup("Not found")
         close()
Error:
org.sikuli.script.FindFailed: FindFailed: can not find C:\Users\268263\Desktop\download files_life insurance\images\ Line 15, in file C:\Users\268263\AppData\Local\Temp\sikuli-tmp6067810858923825859.py

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

this does not do what you expect:

   addImagePath("CC:\\Users\\268263\\Desktop\\download files_life insurance\\images\\")
   imgPath=list(getImagePath())
   for v1 in imgPath:
       if find(v1): **v1 is image searched in u1 PDF **
         m=find(v1).right().text()

--- addImagePath()
adds the given path to the internal list of paths, where GIVEN images are looked for to be used in find operations.
This should never be in a loop, since is added every time.

--- imgPath=list(getImagePath())
does not return the contained image files, but the list of paths, that might contain imgae files

--- error
so consequently v1 contains a path and not an image file name, which leads to the FindFailed exception (the next version will distinguish between "image file cannot be found" (your case) and "the image contained in the image file cannot be found on the screen")

--- solution:
so you have to use functions from the modules os and shutil to generate a list of file names contained in the respective directory, that can be used to check against the PDF

Can you help with this problem?

Provide an answer of your own, or ask swethaa for more information if necessary.

To post a message you must log in.