using WebEdit .Type property cannot be used - vbscript

I have a piece of code in using QTP for a webpage
Browser("Sarit_2").Page("Sarit").WebEdit("frm_vendor_address1").Set dtVAdd1
You will observe, I used a 'Set' property. In reality, I wanted to use a 'Type' property because soon I will write script to check field limit and .Set property throws an error when I try to set a value larger than the field length. But Type property(I used it in win32 app), it types as much as the field length but at least doesn't throw an error I can't handle.
QTP in WebEdit or this particular WebEdit does not allow me to choose .Type. How come it allowed me in the case of SWFfield?
Any suggestions?

"Type" is a method used for Windows application, Delphi, Java, swf etc... But it is not used for Web application.
For web application we have to use "Set" method. Therefore above piece of code accepts 'Set' method. This also tells why you can not use 'Type' method with web based object.
If you want to count the field limit, you can object spy on the webedit-> save its max length value to any variable-> at run time store max length of that web edit field to variable2 using 'Browser("...").Page("..."). .... .GetROProperty("max length"). Now compare the two variable with if statement.

The WebEdit test object is helpfully trying to prevent you from setting an invalid value into the edit field.
You obviously don't want this help the question I'm not clear on is what you're trying to accomplish. If you want to set the first part of the string up to maxlength you can do something like this:
Public Function SetLimit(ByRef test_object, ByRef Value)
max = test_object.GetROProperty("max length")
If Len(Value) > max Then
test_object.Set Left(Value, max)
Else
test_object.Set Value
End If
End Function
RegisterUserFunc "WebEdit", "Set", "SetLimit"

You could use the WScript shell object to send keystrokes to the WebEdit after focussing it (by clicking into it). Like shown in http://h30499.www3.hp.com/t5/Quality-Center-Support-and-News/QTP-cannot-input-value-to-Webedit-field/td-p/4206627#.UkRMyIbIYyg:
Set WshShell = CreateObject("WScript.Shell")
Browser("Sarit_2").Page("Sarit").WebEdit("frm_vendor_address1").Click
WshShell.SendKeys(dtVAdd1)
Set WshShell = Nothing
Note that dtVAdd1's value must then conform to the format SendKeys expects -- as documented in (for example) http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx.
Alternatively, you could use the undocumented Mercury.DeviceReplay interface to send the keystrokes. This is easily googleable.

As we know WebEdit does not supports Type method, we can use alternate approach like
1.SendKeys
Set objClick = CreateObject("WScript.Shell")
Browser("Sarit_2").Page("Sarit").WebEdit("frm_vendor_address1").Click
objClick.SendKeys "dtVAdd1"
Set objClick = Nothing
http://www.ufthelp.com/2013/02/sending-keyboard-strokes-in-uft-115.html
2.Using Native Object properties
Browser("Sarit_2").Page("Sarit").WebEdit("frm_vendor_address1").object.value ="dtVAdd1"
but this is almost similar to Set method
3.Using Advance Run settings in UFT
Tools->options->GUI Testing ->Web->Advance->Run Settings->Replay Type ->Mouse

Related

Cannot set property with previously defined property in botbnt framework composer

I am working on a bot build with Microsoft bot framework composer
I have an HTTP request that works and returns an array of programs
Currently, I have a "0" hard set and that works
${dialog.programlistlite.api_response.content.programs[0].name}
what i am trying to do is take property called dialog.resultnumber which is set to 0 and replace static "0" above with property called dialog.resultsnumber
I tried:
${dialog.programlistlite.api_response.content.programs[${dialog.resultsnumber}].name}
${dialog.programlistlite.api_response.content.programs[(dialog.resultsnumber)].name}
${dialog.programlistlite.api_response.content.programs[dialog.resultsnumber].name}
${dialog.programlistlite.api_response.content.programs[getproperty(dialog.resultsnumber)].name}
${dialog.programlistlite.api_response.content.programs[dialog.resultsnumber()].name}
${dialog.programlistlite.api_response.content.programs[${dialog.resultsnumber()}].name}
I cannot find the syntax to use an already defined property to build a new property
what i am trying to do is take property called dialog.resultnumber which is set to 0 and replace static "0" above with property called dialog.resultsnumber I tried:
Are you sure that dialog.resultsnumber is an int?
If you set it in a single set property action, make sure you set it as an int, the default is a string.
This below should be the one. It worked for me (with the above caveat):
${dialog.programlistlite.api_response.content.programs[dialog.resultsnumber].name}
You can also use the isInteger() type checking function to confirm if something is an int, or try and force/convert/coerce using int() if needed as well.

In VBScript, how can I retrieve the first element of an InstancesOf collection?

I'm writing a VBScript that should identify the OS details. I found an exemple here using InstancesOf Win32_Operating system, but instead of the foreach loop from the sample, I only want to address the first occurence, so I did:
Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
Set System = SystemSet.Item(0)
Also tried Set System = SystemSet(0), but each time I have a generic failure error message (Echec générique in french).
How can I achieve this so I can then compare the System.Caption string?
The GetObject("winmgmts:") returns a SWbemServices object. According to the documentation for the SWbemServices object the InstanceOf() method:
From SWbemServices.InstancesOf method
creates an enumerator that returns the instances of a specified class according to the user-specified selection criteria.
The idea of an enumerator is to enumerate over a collection of objects this lends itself to the VBScript For Each statement for iterating over an enumerator.
A simple example would be;
Dim swbemInstances, swbemInstance
Set swbemInstances = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
For Each swbemInstance In swbemInstances
WScript.Echo swbemInstance.Caption
Next
You can access an instance directly from the enumerator using the ItemIndex method which as the documentation says;
From SWbemObjectSet.ItemIndex method
returns the SWbemObject associated with the specified index into the collection. The index indicates the position of the element within the collection. Collection numbering starts at zero.
Note: Interesting point the documentation actually cites the Win32_OperatingSystem class as an example where you likely want to retrieve only one instance and explains how to use ItemIndex to facilitate it.
From SWbemObjectSet.ItemIndex method - Examples
Only one instance of Win32_OperatingSystem exists for each operating system installation. Creating the GetObject path to obtain the single instance is awkward so scripts normally enumerate Win32_OperatingSystem even though only one instance is available. The following VBScript code example shows how to use the ItemIndex method to get to the one Win32_OperatingSystem without using a For Each loop.
Something like;
Dim swbemInstance
Set swbemInstance = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem").ItemIndex(0)
WScript.Echo swbemInstance.Caption
Also mentioned in the comments

How can we get the value of textbox in QTP?

I am executing the automated test scripts in UFT 12.5 I am new to UFT. Not very familiar with codes.There is an edit box wherein i have to type the value "S05292". Example:
Browser(Browsername").Page("Pagename").WebEdit("ctl00$ConBody$txtPDNumber").Set "S05292"
The problem is my script fails at this step and does not type the value. Can somebody provide me with a solution which is easy to understand. I tried the below two methods
Method (1)
a=Browser().page().webedit(ctl00$ConBody$txtPDNumber).getroproperty("value")
if a=="S05292" then
msgbox ("displayed message is S05292")
else
msgbox ("msg is not S05292")
end if
Method (2)
x = Browser("Browsername").Page("Pagename").Webedit("ctl00$ConBody$txtPDNumber").GetROProperty("value")
msgbox x
The error message that displays is
Cannot identify the object "ctl00$ConBody$txtPDNumber" (of class WebEdit).
Verify that this object's properties match an object currently displayed in your application.
Use the Object Spy to get the properties of that text box at run time and then make sure they match up to the properties of that text box in your object repository that you defined. Perhaps that don't match up or you didn't uniquely identify that text box.
If you don't want to use an object repository then you have to pass it a property at run time to uniquely identify it. Some thing like:
Browser().page().webedit("developer name:=PDNumber").
Instead of a .set you can do a .type to set/type the value into the text box

WScript.CreateObject crashes Windows Scripting Host when event handler prefix is specified for WinHTTPRequest

According to the MSDN documentation WinHTTPRequest has four event handlers which should be accessible by specifying an event handler prefix. Unfortunately, doing so causes Windows Scripting Host to crash.
The following code crashes Windows Scripting Host:
Set oHTTP = WScript.CreateObject( "WinHttp.WinHttpRequest.5.1", "oHTTP_" )
This code works just fine:
Set oHTTP = WScript.CreateObject( "WinHttp.WinHttpRequest.5.1" )
Any thoughts as to why?
It's not part of the specification in any way. Wishful programming rarely works.
Creates and returns a reference to an Automation object.
CreateObject(servername.typename [, location])
Arguments
servername
Required. The name of the application providing the object.
typename
Required. The type or class of the object to create.
location
Optional. The name of the network server where the object is to be created.
If you want to make up your own wishful specifications, see if you can add your own parameters to this one.
From Help for GetRef
Returns a reference to a procedure that can be bound to an event.
Set object.eventname = GetRef(procname)
Arguments
object
Required. Name of the object with which event is associated.
event
Required. Name of the event to which the function is to be bound.
procname
Required. String containing the name of the Sub or Function procedure being associated with the event.

QTP recognising a JavaEdit object but not able to set a value when running the script

I have written a simple script to log into a Java app where it fills in username and password, and then clicks on the "Connect" button".
Set UVC = JavaDialog("UVC")
wait(20)
If UVC.Exist Then
UVC.JavaEdit("JTextField").Set "admin"
wait(2)
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
wait(5)
UVC.JavaButton("Connect").Click
Else
print "Console is not present"
End If
It's strange as QTP is identifying my password field properly. When running the following code I get a value back as expected:
MsgBox Main.JavaEdit("password").GetROProperty("attached_text")
I have also tried to set the password without encrypting it but it's also not working.
PS: the same script was working before and has since stopped working for an unknown reason!!!
Thanks in advance.
Replace
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
with
UVC.JavaEdit("PSW").Click 1,1
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
and it will work even with replay mode = "event". If you want to beautify this, you can use a click in the middle of the field, like in:
With UVC.JavaEdit("PSW")
.Click .GetROProperty ("width")\2, .GetROProperty ("height")\2
.SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
End With
It seems that most Java password fields must first be focussed to be SetSecure-able.
Just to be sure.. check whether the field is enabled by testing .getroproperty("editable").
Use any of these methods to set text in Java Edit field.
You could use JavaEdit("PSW").Object.Settext method - this uses the JTextField in JavaSwing object properties
You could use setfocus method before entering the string in the field
Get the position of the test field
x = JavaEdit("PSW").Getroproperty("abs_x")
y = JavaEdit("PSW").Getroproperty("abs_y")
Set DRP = CreateObject("Mercury.DeviceReplay")
DRP.MouseClick x,y,"0"
DRP.SendString "the string"
You could also use JavaEdit's type object
Any of these methods should work for you. If not tough luck.. :)
Thanks for your answers but none of your suggestions worked, I have ended up using a basic turnaround :
UVC.JavaEdit("JTextField").Set"admin"
UVC.JavaEdit("PSW").Click 1,1
UVC.JavaEdit("PSW").SetSecure"52581237d889935df36ae78587773a641f40"
UVC.JavaButton("Connect").Click
wait (5)
While JavaDialog("Login Error").Exist
JavaDialog("Login Error").JavaButton("Ok").click
UVC.JavaEdit("PSW").RefreshObject
UVC.JavaEdit("PSW").SetSecure"52581237d889935df36ae78587773a641f40"
UVC.JavaButton("Connect").Click
Wend
I really don't get it how could the same function work sometimes and sometimes not!!

Resources