From: Praveen Kumar Date: 2008-08-26T03:06:25+09:00 Subject: How to read text in a Wsh window 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("^(c)") 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? -- Posted via http://www.ruby-forum.com/.