Micro Focus QTP (UFT) Forums
Copy content from a text file & paste it in text area in a web page - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Copy content from a text file & paste it in text area in a web page (/Thread-Copy-content-from-a-text-file-paste-it-in-text-area-in-a-web-page)



Copy content from a text file & paste it in text area in a web page - qtpnewbie1 - 12-02-2008

Hi,

Can anyone please tell me how to automate copying the content from a text file and pasting it on a text area of a web browser?

The code I have tried copies the content and pastes it on the QTP expert view as a huge line. It is a big text file and I don't want the content to be copied as inline text in QTP. Is this possible?

Please Help!


RE: Copy content from a text file & paste it in text area in a web page - roxer - 12-02-2008

Hi
Yes, it's possible.
Before running test you can save text, that should be copied, to some text file.
Below code that opens this file and reads it's content to some variable. As I understand, you know how to paste text in text area of browser, and you just need code how to read text from file.
I write function for you that receives pathToFile as argument and returns text, that this file contains:
Code:
Function readTextFromFile(pathToFile)
  'creating File System Object
  Set fso = createObject("Scripting.FileSystemObject")
  If fso.FileExists(pathToFile) = True Then
   'open text file for reading
   Set f = fso.openTextFile(pathToFile, 1)
   'read all text from file and return it to function
   readTextFromFile = f.ReadAll
   'close file
   f.Close
  End If
End Function

Using this function:
Code:
text = readTextFromFile(filePath)



RE: Copy content from a text file & paste it in text area in a web page - qtpnewbie1 - 12-05-2008

Thank you so much. It worked. Thanks again.