Using Pywinauto to automate ABBYY, I get "ElementNotFoundError"

180 views Asked by At

I am trying to use pywinauto to use the progam ABBYY FineReader. I am using the following code (based on this YouTube tutorial https://www.youtube.com/watch?v=R4E4IOIC63s):

from pywinauto.application import Application

Application(backend = 'uia').start(r'C:\Program Files (x86)\ABBYY FineReader 15\FineReaderOCR.exe', timeout = 5)

app = Application(backend = 'uia').connect(title = 'Untitled Project - ABBYY FineReader PDF 15 OCR Editor')

After running the last line, I get the following error:

Traceback (most recent call last):

  File "C:\Users\ariel\AppData\Local\Temp\ipykernel_6460\814936370.py", line 1, in <module>
    app = Application(backend = 'uia').connect(title = 'Untitled Project - ABBYY FineReader PDF 15 OCR Editor')

  File "C:\Users\ariel\anaconda3\envs\pdf_parser_env\lib\site-packages\pywinauto\application.py", line 997, in connect
    self.process = findwindows.find_element(**kwargs).process_id

  File "C:\Users\ariel\anaconda3\envs\pdf_parser_env\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
    raise ElementNotFoundError(kwargs)

ElementNotFoundError: {'title': 'Untitled Project - ABBYY FineReader PDF 15 OCR Editor', 'backend': 'uia', 'visible_only': False}

When I do the canonical Notepad example, I don't get any error:

note = Application(backend = 'uia').start(r'notepad.exe').connect(title= 'Untitled - Notepad', timeout = 2)

I've played around with the code using other postings with similar problems on here and other forums, but I can't figure out what exactly might be going on and I can't get around this error. Is there something wrong with my code or are there some programs that won't allow you to use pywinauto?

1

There are 1 answers

0
ihatecomputers On

Based on the comments by Vasily Ryabov, I used

print([w.window_text() for w in Desktop(backend="uia").windows()])

And copied and pasted the name of the window and added the timeout option for good measure:

app = Application(backend = 'uia').connect(title = 'Untitled project - ABBYY FineReader PDF 15 OCR Editor', timeout = 5)

I now see I had simply capitalized "project" unnecessarily.