# How to read text in a Wsh window

**URL:** <https://www.ruby-forum.com/t/how-to-read-text-in-a-wsh-window/146813>\
**Category:** Ruby\
**Created:** [August 25, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/how-to-read-text-in-a-wsh-window/146813 "2008-08-25T20:10:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkammit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8c91f0/32.png) [@pkammit](https://www.ruby-forum.com/u/pkammit)\
**Post date:** [August 25, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/how-to-read-text-in-a-wsh-window/146813/1 "2008-08-25T20:10:44Z")

</div>

Hi everyone, I am a QA guy and I use watir for testing web applications.  
In my testing I sometimes have to work on a Windows application also.  
Using WIN32OLE, I am able to access the Windows application and perform  
actions in it by sending keystrokes, text, etc. I am able to perform the  
task that I need to but it would be nicer if I could verify that  
confirmation message is shown in the application when my task is  
completed.  
I am wondering if there is a way to capture the text in the window and  
write it to a text file.

This is the code I use to access the application

#create an instance of the Wscript Shell object:  
wsh = WIN32OLE.new(‘Wscript.Shell’)  
#activate the window identifying it with title  
wsh.AppActivate(“Myapp-title”)  
#Here you enter your login Id and Password  
wsh.SendKeys(‘userid{ENTER}’)  
sleep(1)  
wsh.SendKeys(‘Password{ENTER}’)

Here I tried the following, but it didn’t work.  
Open up a notepad document.  
Do ctrl+a, and ctrl+c in the first window.  
Then go to the notepad document and do ctrl+v to paste the text that is  
captured from the application.  
If I manually execute the steps listed above,I am able to copy the text.  
But the same steps executed through the script do not produce the  
desired result.

#Open up a notepad document  
shell.ShellExecute(‘notepad.exe’, ‘’, ‘’, ‘open’, 1)  
sleep(1)

#activate the first window again because I just opened a notepad and  
focus #might have been lost  
wsh.AppActivate(“Myapp-title”)  
#Control + A to grab all text in the application window  
wsh.SendKeys("%(a)")  
sleep(1)  
#Control + C to copy the text  
wsh.SendKeys("^©")  
sleep(1)

#now shift focus to the notepad document

wsh.AppActivate(“Untitled”)  
#Control + V to paste text captured from the app to the notepad  
document.  
wsh.SendKeys("^(v)")

What I tried is just a long shot and it didn’t work. Is there any other  
way to capture text from the windows applicaiton? Can someone please  
share their code if they have been able to perform this?
