akkab
akkab

Reputation: 401

Handling "Windows Security" window with pywinauto

I am writing a program to connect to the Remote Desktop Connection automatically. So, up untill now I was successfull in getting the application up and running and have the Computer Name written into the text box. Then, I am able to automatically click submit btn. Here is the code:

import pywinauto
from pywinauto.application import Application

app = Application().start("mstsc.exe")

computerName = "computer_name"
password = "password"

app['Dialog']['Edit'].type_keys(computerName, with_spaces=True)
app['Dialog']['Connect'].click()

This is the window where all the aforementioned stuff is done: enter image description here

The next thing that pops-up after hitting Connect button is the Windows Security, where I need to input password (automatically). However, I am not sure, how should python identify the controls of that window and especially the Password text field:

enter image description here

So far I have tried to indetify it by its title, but unsuccessfully:

windowsSecurity = pywinauto.findwindows.find_windows(title_re = r"Windows Security")

--------------------------------- SOLUTION --------------------------------

Just solved the issue using the following way. Firstly I identified what are the controls of the window that pops up, but before that, I am leaving some pause time for it to come on surface. Secondly, using the controls that I have identified, I send the keys and send click command. Here is the list of controls that I got by dlg.print_ctrl_ids()

| | Edit - '' (L656, T323, R1100, B371) | | ['Surname, NameEdit', 'Edit'] | | child_window(auto_id="PasswordField_2", control_type="Edit") | | |

computerName = "computer"
password = "password"
app = pywinauto.application.Application(backend="uia")
app.start('mstsc.exe')

dlg = app.window(title_re="Remote Desktop Connection")
dlg['Edit'].type_keys(computerName)
dlg['Connect'].click()

time.sleep(5)

if dlg.child_window(title="Windows Security",control_type="Window").exists():

    windows_security = dlg.child_window(title="Windows     Security",control_type="Window")
    dlg['PasswordField_2'].type_keys(password)    
    dlg.child_window(auto_id='OkButton').click_input()
else:
    print("Wait time exceeded")

Upvotes: 0

Views: 1648

Answers (2)

Ahmadgbg
Ahmadgbg

Reputation: 13

Solved this by using:

Import Desktop:

from pywinauto import Desktop

Then in the code:

windows_security = Desktop(backend="uia").window(title="Windows Security")

Found the solution in this GitHub issue.

Upvotes: 1

akkab
akkab

Reputation: 401

Just solved the issue using the following way. Firstly I identified what are the controls of the window that pops up, but before that, I am leaving some pause time for it to come on surface. Secondly, using the controls that I have identified, I send the keys and send click command. Here is the list of controls that I got by dlg.print_ctrl_ids()

| | Edit - '' (L656, T323, R1100, B371) | | ['Surname, NameEdit', 'Edit'] | | child_window(auto_id="PasswordField_2", control_type="Edit") | | |

computerName = "computer"
password = "password"
app = pywinauto.application.Application(backend="uia")
app.start('mstsc.exe')

dlg = app.window(title_re="Remote Desktop Connection")
dlg['Edit'].type_keys(computerName)
dlg['Connect'].click()

time.sleep(5)

if dlg.child_window(title="Windows Security",control_type="Window").exists():

    windows_security = dlg.child_window(title="Windows         Security",control_type="Window")
    dlg['PasswordField_2'].type_keys(password)    
    dlg.child_window(auto_id='OkButton').click_input()
else:
    print("Wait time exceeded")

Upvotes: 1

Related Questions