Micro Focus QTP (UFT) Forums
What is the problem with this code? Pls reply ASAP - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: What is the problem with this code? Pls reply ASAP (/Thread-What-is-the-problem-with-this-code-Pls-reply-ASAP)



What is the problem with this code? Pls reply ASAP - kkishore12345 - 12-09-2008

Hi All,

Can anyone answer this question please?

I am trying to capture the Privacy policy of Google and store in a Text file.

I have written the following code.

Code:
If browser("Google").Page("Google").Image("Google").Exist Then
    reporter.ReportEvent micDone, "google page", "google page is found"
    else
    reporter.ReportEvent micDone, "google page", "google page not found. Exiting"
    ExitAction()
End If
If browser("Google").Page("Google").Link("Privacy").Exist Then
    reporter.ReportEvent micDone, "Google privacy", "google privacy link found"
    else
    reporter.ReportEvent micDone, "google privacy", "google privacy link not found.Exiting"
    ExitAction()
End If
If browser("Google").Page("Google").Link("Privacy").Exist Then
    browser("Google").Page("Google").Link("Privacy").Click()
End If
If browser("Google").Page("Privacy Center").Link("Privacy Policy").Exist Then
    reporter.ReportEvent micDone, "Privacy center", "Privacy center page found"
    else
    reporter.ReportEvent micDone, "Privacy center", "privacy center page not found. Exiting"
    ExitAction()
End If
If browser("Google").Page("Privacy Center").Link("Privacy Policy").Exist Then
    browser("Google").Page("Privacy Center").Link("Privacy Policy").Click()
End If

If browser("Google").Page("Privacy Policy – Google").WebButton("Search").Exist Then
    reporter.ReportEvent micDone,"Privacy policy", "you are in the right page"
    else
    reporter.ReportEvent micDone,"Privacy policy", "You are in the wrong page"
End If
Dim str
If browser("Google").Page("Privacy Policy – Google").WebButton("Search").Exist Then
    str=browser("Google").Page("Privacy Policy – Google").GetROProperty("innertext")
  
End If
Dim fso, File1, File2
Set objFSO=CreateObject("Scripting.FileSystemObject")
objFile1=FSO.CreateTextFile("C:\testfile.txt", true)

Const ForWriting=2
Set objFSO=CreateObject("Scripting.FileSystemObject")
objFile2=FSO.OpenTextFile("C:\testfile.txt", ForWriting, True)

objFile1.write str

All the lines are executed successfully till it reaches CreateTextFile line.

Please let me know what did I miss in the above code?

Earliest reply is highly appreciated!
Thanks,
Kishore


RE: What is the problem with this code? Pls reply ASAP - seetu - 12-09-2008

Dear Kishore Every thing is fine what you need to do is
Objects which u created names are mismatching so correct all names then u can run smoothly.
Code:
Dim fso, objFile1, objFile2
Set objFSO=CreateObject("Scripting.FileSystemObject")
objFile1=objFSO.CreateTextFile("C:\testfile.txt", true)

Const ForWriting=2
Set objFSO=CreateObject("Scripting.FileSystemObject")
objFile2=objFSO.OpenTextFile("C:\testfile.txt", ForWriting, True)
objFile1.write str

here is the code
let me kwow ur resukts


RE: What is the problem with this code? Pls reply ASAP - kkishore12345 - 12-09-2008

Dear Seetu,

Thanks for your response. However, I am getting 2 errors. #1.Permission denied #2.Object required. Please provide any possible solution to solve this.

Looking forward to hear from you,
Kishore


RE: What is the problem with this code? Pls reply ASAP - seetu - 12-09-2008

Dear Kishore
Here is the code for the same
Code:
Dim obfso, objFile1,objFile2
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile1=objFSO.CreateTextFile("C:\testfile.txt", true)
objfile1.close

Const ForWriting=2
Set objFSO=CreateObject("Scripting.FileSystemObject")
set objFile2=objFSO.OpenTextFile("C:\testfile.txt", ForWriting, True)

objFile2.write str


I think it works
let me know if u need further assistance.


RE: What is the problem with this code? Pls reply ASAP - kkishore12345 - 12-09-2008

Dear seetu,

Thanks for your reply. But, unfortunately I am getting the same error mesgs, unable to move further.
Please suggest some other solution


RE: What is the problem with this code? Pls reply ASAP - seetu - 12-09-2008

Dear Kishore pls use the following code.
it is working fine in my Environement.

Code:
Dim objFSO,objFile1,objFile2
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile1=objFSO.CreateTextFile("C:\testfile.txt", true)
objfile1.close

Const ForWriting=2
Set objFSO=CreateObject("Scripting.FileSystemObject")
set objFile2=objFSO.OpenTextFile("C:\testfile.txt", ForWriting, True)

objFile2.write str
objFile2.close



RE: What is the problem with this code? Pls reply ASAP - kkishore12345 - 12-10-2008

I am getting "Permission denied" error message. However, I tried in my Office, I was able to create a Text file. Later, by right clicking its properties, I have changed the permission, then I was able to get all the text which I captured from the web page. But on my laptop, I am unable to create a file. I have changed the permission settings for the folder, Temp also. Any suggestions?