Reputation: 11
I am trying to automate some basic Putty activities such as login to the system and type a few commands using pywinauto. Just to let you know - I don't think paramiko/netmiko can help with this as I need the window stay (GUI) on the screen so that I can carry on working on the same window opened as a result of the code run.
My code starts the session to the given ip (10.22.22.222). However, I get some dialog windows such as Security Alert (if it is the first time I login to a given machine) or Fatal Error (if the device is unreachable or connection refused) at times. Does anyone know how I can handle/press buttons on this window like Yes, No, Cancel, OK or just Close on the top right corner.
My code snippet is as follows:
app = Application().Start('C:\\Users\\redback\\Desktop\\putty.exe -ssh [email protected]')
pt = app.PuTTY
pt.Wait ('ready')
time.sleep (40) # tried to wait 40 secs (more than the default timeout of 30 secs)
pt.PuTTY.OK.click() # and press OK on the PuTTY Fatal Error pop-up window
# ideally I would carry on with Alt+F4 or Close so that I can clean it off the screen
Many thanks.
Upvotes: 0
Views: 1145
Reputation: 31
I think the code below should handle pop-up window.
app = Application().Start(r"C:\Program Files\PuTTY\putty.exe -ssh [email protected]")
pt = app.PuTTY
pt_sec_alert = app.PuTTYSecurityAlert
pt.wait('ready')
time.sleep(5)
if pt_sec_alert.exists():
# pt_sec_alert.Yes.click()
# pt_sec_alert.No.click()
pt_sec_alert.Cancel.click()
This is example for Security Alert window, for Fatal Error it will be the same I think.
Upvotes: 1