user3058854
user3058854

Reputation: 43

How to read text from an application window using pywinauto

I have a python code which opens a SSH session using Putty and passes a command to reboot a remote machine using pywinauto. I want to read the text from the putty terminal after typing the password and compare it Is there a way I can do it? Below is the piece of code for the same

    app_Putty = application.Application()
    app_Putty.start_("C:\Users\debajyoti.bose\Downloads\putty.exe")
    app_Putty.top_window_().TypeKeys(IP)
    app_Putty.top_window_().TypeKeys("{TAB}"+"22")
    app_Putty.top_window_().RadioButton4.Click()
    app_Putty.top_window_().OpenButton.Click()
    time.sleep(10)
    app_Putty.top_window_().NoButton.Click()
    time.sleep(2)
    app_Putty.top_window_().TypeKeys(user+"{ENTER}")
    time.sleep(3)
    app_Putty.top_window_().TypeKeys(password+"{ENTER}")
    time.sleep(3)
    app_Putty.top_window_().TypeKeys("/bin/reboot"+"{ENTER}")
    time.sleep(5)
    app_Putty.kill_()
    time.sleep(120)

I am using pywinauto v0.4.0 Thanks in advance.

Upvotes: 2

Views: 7921

Answers (2)

Matthew Swaringen
Matthew Swaringen

Reputation: 349

You can't capture directly like this from what I can tell, but I had to find a workaround, and the one I found was this

#clear the buffer with alt space menu 
app.window(title='PuTTY - Title').type_keys('% l',with_spaces=True)

#copy the buffer to clipboard 
app.window(title='PuTTY - Title').type_keys('% o',with_spaces=True)

I was having to do this because the putty.log file was missing the selection indicator icon (asterisk) on the screen when it was logging output and I needed a way to know which item was selected to move up or down.

Upvotes: 0

Vasily Ryabov
Vasily Ryabov

Reputation: 9991

OK, let's try app_Putty.top_window_().WindowText(). If it fails your mission looks impossible.

Upvotes: 2

Related Questions