Vbscript GetObject Returns Unspecified Error - vbscript

I'm new to vbscript and i'm writing an application to:
open internet explorer
insert search text
click search button
get result count text
So far i have:
Dim obj
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "www.google.com"
WScript.Sleep 4000
IE.Document.getElementById("lst-ib").value = "Test"
IE.Document.Forms(0).Submit()
WScript.Sleep 4000
Set IE = GetObject("","InternetExplorer.Application")
obj = IE.Document.All.item("resultStats").InnerText
MsgBox obj
However, if i run this i get the following error:
Error: Unspecified error
Code: 80004005
I don't know what could be wrong.
Can anyone help me?
Thanks

Related

How to fix error of "Object connection lost from its client" in VBscript"?

my code where I try to login into the website automatically. But it keeps on throwing
The object is lost connection from its client
Dim IE
set IE = WScript.CreateObject("InternetExplorer.Application")
IE.Visible = true
Call IE.navigate("http://finrpa:8080/controlroom/")
Do While IE.ReadyState <> 4
WScript.Sleep 10
Loop
IE.Document.all.username-inputEl.Value = "parthiban.nadar#thirdware.com"
IE.Document.all.password-inputEl.Value = "Thirdw#re1"
Call IE.Document.all.gaia_loginform.submit
Set IE = Nothing
What line the exception is thrown?
I see at least one problem with the script. Because the control names contain dashes, they should be strings. So, instead of
IE.Document.all.username-inputEl.Value = "parthiban.nadar#thirdware.com"
IE.Document.all.password-inputEl.Value = "Thirdw#re1"
should be
IE.Document.getElementById("username-inputEl").Value = "parthiban.nadar#thirdware.com"
IE.Document.getElementById("password-inputEl").Value = "Thirdw#re1"

QTP AOM code to enable image capture on script failure is not working

QTP AOM code to enable image capture on script failure is not working
I am using the below code to enable the QTP Screen Capture option but it's not storing any screenshots:
Code:
Dim App
Dim qtTest
'Create the QTP Application object
Set App = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If App.launched <> True then
App.Launch
End If
'Make the QuickTest application visible
App.Visible = True
'Set QuickTest run options
'Instruct QuickTest to perform next step when error occurs
App.Options.Run.ImageCaptureForTestResults = "OnError"
App.Options.Run.RunMode = "Fast"
App.Options.Run.ViewResults = True
'Open the test in read-only mode
App.Open "D:\GUITest4", True
'set run settings for the test
Set qtTest = App.Test
'Instruct QuickTest to perform next step when error occurs
qtTest.Settings.Run.OnError = "NextStep"
'Run the test
qtTest.Run
'Check the results of the test run
MsgBox qtTest.LastRunResults.Status
' Close the test
qtTest.Close
'Close QTP
'App.quit
'Release Object
Set qtTest = Nothing
Set App = Nothing
Can anyone help?
Try this to capture screenshots:
set obj = Desktop
obj.capturebitmap strFileName & ".png"
To have the screenshot embedded in results itself, give the path of results in strFileName parameter as:
strFileName = Environment.Value("ResultDir") & "\" & Mid(Environment.Value("ActionName"), 1, 15) & filename.png
Using QTP AOM we can capture the screenshot which will be stored in the results folder , can be controlled via below code.
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Open "C:\Tests\Test1", True
Set qtTest = qtApp.Test
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1"
Set the results location
qtTest.Run qtResultsOpt
Run the test
qtTest.Close
Hope it helps, let me know the results

Verify what website I am currently on

Does anyone know of a quick and easy way to verify what website I'm currently on?
I have made some script that logs me into a website, but if the user is already logged on, it will create an error.
If anyone knows a good way to tell if they are already logged in, please let me know!
The script is as follows:
Username = InputBox("Please input username")
Password = InputBox("Please input password")
Set objShell = WScript.CreateObject("WScript.Shell")
Dim IE
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
IE.Visible = 1
IE.navigate "http://wsmmart.itg.ti.com/"
Do
WScript.Sleep 250
Loop While IE.ReadyState < 4 And IE.Busy
IE.Document.All.Item("fld2").Value = Username
IE.Document.All.Item("fld5").Value = Password
'IE.Document.All.Item("Submit").Click
The following code will loop through all open IE windows and look to see if any one of them has the term "wsmmart.itg.ti." in the url. If it finds a match it will control that window and proceed to insert your username, pw, etc. If it doesn't find a match then you could run your code to open a new window
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).Document.Location
If my_url Like "*" & "wsmmart.itg.ti." & "*" Then 'find an existing wsmmart web page
Set ie = objShell.Windows(x)
Exit For
Else
if x=(IE_count - 1) then
' do your stuff to open a new window
end if
End If
Next
on error goto 0
now try to insert your username, pw, etc. , put it in an if statement. if you get an error back, then you're already logged in

VBScript Code: Object required error

Guys
I just wrote a vbs code snippet to automatically post in a forum. That's just for convenience. I encountered a wired problem:
I have several accounts. When I login as some accounts and use the script to automatically post, everything is OK. However, when I login as the other accounts and run the script, I got the error:
Error : Object required "getElementById(...)"
Code : 800a01a8
Source : Microsoft VBScript runtime error
I'm sure the object exists because I get it in the source of the webpage. I feel the error occurred randomly and I cannot get the regularity.
The script is ran in a Windows 8 OS and the browser is IE9. I'm a new learner of vbs and I don't know how to debug it. So I hope someone can help me. You can give me some clue.
Here is my code snippet:
Option Explicit
Dim IEApp
Dim iURL1
Dim iURL2
Dim iURL3
Dim iURL4
Dim iURL5
Set IEApp = CreateObject("InternetExplorer.Application")
iURL1="http://bbs.dealmoon.com/thread-299027-1-1.html"
iURL2="http://bbs.dealmoon.com/thread-299195-1-1.html"
iURL3="http://bbs.dealmoon.com/thread-299018-1-1.html"
iURL4="http://bbs.dealmoon.com/thread-299015-1-1.html"
iURL5="http://bbs.dealmoon.com/thread-299014-1-1.html"
Open iURL1
Open iURL2
Open iURL3
Open iURL4
Open iURL5
WScript.Echo("Done!")
Sub Wait(IE)
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy
End Sub
Sub Post(IE)
Dim count
For count=0 To 9
With IE.Document
.getElementById("fastpostmessage").innerHTML = "good"
.getElementById("fastpostsubmit").click
Wait IE
WScript.Sleep GetRandom(7,15)
End With
Next
End Sub
Sub Open(PageURL)
IEApp.Visible = False
IEApp.Navigate PageURL
Wait IEApp
Post IEApp
End Sub
Function GetRandom(floor,ceil)
Randomize
GetRandom=Int((ceil - floor + 1) * Rnd + floor)*1000
End Function
You should call your POST routine after all the HTML content is loaded, for example in DOMContentLoaded or window.onload (for IE<9).
You dimmed IEApp, created the object, but you are not using it when trying to get the element ID. Your With block should look like this:
With IEApp.Document
.getElementById("fastpostmessage").innerHTML = "good"
.getElementById("fastpostsubmit").click
Wait IEApp
WScript.Sleep GetRandom(7,15)
End With
There are a few other places you only have IE instead of IEApp. Clear those up and your code should run fine.

QTP Link object does not support the Exist property

I have a weird problem with QTP 11. The following piece of code worked so far, but suddenly stopped working and throws Object does not support this property or method.: 'objPage.Link' for the line with 'if link exist'
Set objBrowser = Browser("creationtime:=" & Desktop.ChildObjects(oDesc).Count - 1 & "")
Set objPage = objBrowser.Page("title:=.*")
If objPage.Link("class:=menu_link_tab_.*", "html id:=.*DesktopTab").Exist(3) Then
msgbox "ok"
End If
Can anyone tell me what is wrong and/or how to do it right?
EDIT: I solved this but still have no idea what happened. I just cut this part from QTP script and pasted it into Notepad and then copied it from Notepad to QTP. Everything works fine. I did not change anything... Any ideas what the hell happened are welcomed.
ANOTHER EDIT: The problem reappears randomly. With no changes to anything I can just run the test 10 times to have it fail randomly with the 'Object does not support this property or method' message
I have a startBrowser function where I set the objPage and objBrowser :
Function startBrowser(vURL)
Dim oDesc
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate vURL
Window("hwnd:=" & IE.HWND).Maximize
Set oDesc = Description.Create
oDesc( "micclass" ).Value = "Browser"
If Desktop.ChildObjects(oDesc).Count > 0 Then
Set objBrowser = Browser("creationtime:=" & Desktop.ChildObjects(oDesc).Count - 1 & "")
End If
Set objPage = objBrowser.Page("title:=.*")
End Function
I have added lots of msgboxes with GetROProperty to verify whether the objects are ok. They seem to be.
Now my function to click the link looks like this :
Function clickMainMenuLink(vIdentifier)
Set objLink = objPage.Link("class:=menu_link_tab_.*", "html id:=.*" & vIdentifier, "index:=0")
If objLink.Exist(timeOut) Then
objLink.Click
Else
reporter.ReportEvent micFail, "Click the " & vIdentifier & " menu link", "Cannot find the " & vIdentifier & " menu link"
ExitTestIteration
End If
End Function
So at the moment my test just opens the browser and clicks a link as I try to debug the thing, but it still fails or passes randomly. The run error indicates line with 'Set objLink'. Any ideas for further debugging? I'm on QTP11 and IE8 if it matters.
From your error does not support this property or method: objPage.Link it would appear that the problem isn't with the .Exist part of line but the .Link part (you can verify this by separating the line into two lines and see which fails
set objLink = objPage.Link("class:=menu_link_tab_.*", "html id:=.*DesktopTab")
If objLink.Exist(3) Then
From your comment it seems that you're creating objPage in a different location from where you're using it, I suggest making sure that the object arrives OK.
Thanks Motti, your reasoning was right. The problem was with the objPage part. Despite the fact that I could read every property of objPage in a function QTP sometimes just did not see this objPage as a Page object. I guess it has something to do with not declaring type explicitly, but that's just a guess. As a dirty workaround I set up the objBrowser and objPage in every function now and it works 100%.

Resources