3

I have an batch file that I execute that opens a program. A dialog box then appears which I type into it the username and password credentials

The I print the control identifiers and it lists;

SunAwtDialog - 'Login'    (L528, T242, R853, B501)
['SunAwtDialog', 'LoginSunAwtDialog', 'Login']
child_window(title="Login", class_name="SunAwtDialog")

So after reading this post. My understanding was to use window + the button and a click method like so;

dlp.SunAwtDialog['Login'].click()

But this keeps throwing an ElementNotFoundError;

ElementNotFoundError: {'best_match': 'SunAwtDialog', 'top_level_only': False, 'parent': <win32_element_info.HwndElementInfo - 'Login', SunAwtDialog, 2164976>, 'backend': 'win32'}

Below is the full snippet of code;

from pywinauto import application
import time
app = application.Application()
app.start(r"C:\\WINDOWS\system32\cmd.exe", wait_for_idle=False)
dlg = app.top_window()
dlg.type_keys('D:{ENTER}')
dlg.type_keys('cd{SPACE}Software\\client{ENTER}')
dlg.type_keys('run_client.bat{ENTER}')
time.sleep(10)
new_app = application.Application().connect(title="iManager")
dlp = new_app.top_window()
#type username + password
dlp.type_keys('user')
dlp.type_keys('{TAB}')
dlp.type_keys('pass')
#print control identifiers
dlp.print_control_identifiers()
#click login[![enter image description here][1]][1]
dlp.SunAwtDialog['Login'].click()

You can see on the image below the "Login" button I want to be able to click. There is also another button next to the "Server" option, but it is not in my control identifiers

Dialog box

mp252
  • 453
  • 1
  • 6
  • 18
  • You can see in the error that `'backend': 'win32'`. You may try to use `Application(backend="uia")` and `Inspect.exe` as a spy tool. This is all described in the [Getting Started Guide](https://pywinauto.readthedocs.io/en/latest/getting_started.html). – Vasily Ryabov Feb 13 '19 at 14:44
  • This issue with that was that when I attempted it with `backend="uia"` it threw an error saying `ElementNotEnabled` – mp252 Feb 13 '19 at 14:53
  • Sorry @VasilyRyabov ignore me, got the correct control identifiers up now. Also another question, if it needs to be moved to a separate one please let me know. But does this package work well with a java built application? As I had problems with the last tool I was using and that was specific to RPA – mp252 Feb 13 '19 at 14:57
  • It depends which Java framework was used to build the GUI. As I remember JavaFX supports MS UI Automation API pretty well (yes, it's OS level API, pywinauto just wraps it around with some syntax sugar). Not sure about Swing/AWT apps as they are pretty old. – Vasily Ryabov Feb 13 '19 at 21:51
  • `Inspect.exe` uses MS UI Automation API as well (you need to switch to "UI Automation" mode). This is almost the only indicator of GUI testability now. – Vasily Ryabov Feb 13 '19 at 21:53
  • Thank you, I will try it `Inspect.exe` out as at the moment, the only button I can get to click is the `Cancel` button. – mp252 Feb 14 '19 at 09:03

2 Answers2

1

A solution that I use for this is using send_keys. Try this:

from pywinauto.keyboard import send_keys
send_keys("{VK_MENU down}" "l" "{VK_MENU up}")
qbbq
  • 347
  • 1
  • 15
0

The good solution for this is pressing the "Enter" if there is only an "OK" button on that Dialog/Message/Alert/Information box. For this you can use:

send_keys("{ENTER}")

If that doesn't work correctly, you can use the sleep command to wait for 1-2 seconds and then press enter, like so:

time.sleep(2)
send_keys("{Enter}")

For this, you have to import two libraries:

from pywinauto.keyboard import send_keys
import time
Chaoz
  • 2,119
  • 1
  • 20
  • 39