How can we get the value of textbox in QTP? - hp-uft

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

Related

HP-UFT object not found in object repository error

Getting the following error while executing script:
WebList object was not found in the Object Repository.
Check the Object Repository to confirm that the object exists or to find the correct name for the object.
Line (1221): "objParent.WebList(vstrObjectName).select vstrValue".
I understand, it shouldn't be as simple as the object isn't available in the repository but in in case- Try to use 'Locate in repository'
It looks like Line (1221) is trying to access a WebList object by name, but the name is stored in a variable; it is not a string literal in the code.
There might be 3 different things going on here.
1) if you were attempting to use Descriptive Programming, then it sounds like the contents of vstrObjectName didn't include the ":=" symbol that would make QTP believe the string is a description... So, QTP thinks the string stored in vstrObjectName must be the name of an object in the Object Repository.
I would like to guess that you were trying to use descriptive programming, since (based on the fact that the parent, and the parameter are also both contained in variables) it looks like you are avoiding using any string literals in that line.
2) If you were attempting to control an object with a name from the Object repository, then either the string contained in vstrObjectName didn't contain a valid object name (that belongs to objParent), or
3) the object refered to by objParent isn't the one you were expecting.
In any of these cases, if it were me, the first thing I would do is add a print statement before line 1221 as:
Print "vstrObjectName:'" & vstrObjectName & "'"
...and run it again. That should show the string that you were referencing. I would guess that the resulting output line is not what you expected.
Another thing to check is to make sure that the action or function that contains that line is executed from within an action that contains that named object in it's OR scope. (i.e. open the action and hit CTRL-R, it shows the combined OR that is visible to that action). If the line is in a function library, and it gets called from an action that doesn't have the object in it's local OR, or an attached shared OR, then you will get the same error. This kind of problem is very easy to cause if you use multiple actions, and the action containing the call to the function that contains your line (line 1221) doesn't actually have that object available to it due to it's OR scope.
To answer the question you asked - how to add object into the OR - you could use several methods - recording, guispy's add to OR button, manually add from the OR screen, etc... but in the end, you need that object in the OR to have a name that matches whatever is in vstrObjectName.
Some potential examples where an object can be selected:
Dynamically change the object based on the name of the object in the object repository:(must exist in the repository)
Dim objectname
objectname = "SAP Work Manager"
msgbox WpfWindow(objectname).Exist
Select an object that does not exist in the Object repository, by its properties:
WpfWindow("text:=SAPWorkManager").Exist
Example page of UFT tips

Item missing from WebList

I am writing auto test scripts in QTP (UFT).
I have multiple columns in an external datasheet which could contain data or be blank. I was trying write some code, that if it was blank to click a submit button, if not blank then add in the fields. Please see code below:
If IsNull(DataTable("Available_Qualifications_1", dtLocalSheet)) = False then
Browser("Create Qualification Types").Page("Create Qualification Types").WebList("qavailable").Select DataTable("Available_Qualifications_1", dtLocalSheet)
Browser("Create Qualification Types").Page("Create Qualification Types").Link("Add Qualifications").Click
ElseIf IsNull(DataTable("Available_Qualifications_1", dtLocalSheet)) then
Browser("Create Qualification Types").Page("Create Qualification Types").WebButton("Submit").Click
End if
However, I receive the error below:
Cannot identify the specified item of the qavailable object. Confirm that the specified item is included in the object's item collection.
Line (16): "Browser("Create Qualification Types").Page("Create Qualification Types").WebList("qavailable").Select DataTable("Available_Qualifications_1", dtLocalSheet)".
What UFT is saying is that you're trying to set a value into the WebList which isn't one of the WebList's options.
Try outputing the value to see if UFT is correct, if it is then correct your test (by entering the correct values in the data table). If it's not correct you can try using the index by using the Select "#3" syntax (and report the problem to HP's support).

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!!

using WebEdit .Type property cannot be used

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

QTP - if object exists in object repository

In QTP is there any way in the code to check to see if a specific object exists in the object repository. I have tried the following code:
If JavaWindow(className).JavaDialog(dialogName).Exist Then
doThisStuff
Else
doThisStuffInstead
End If
But from what I have gleamed from the Internets, this is similar to a isVisible method, only resulting in true if the specified object is currently visible. When I use the above code I receive a "JavaDialog object was not found in the Object Repository." Is there a method or any way to prevent this very error and check to see if the object does indeed exist?
Thank you for your time
I'm not sure what you're trying to accomplish here, one typically knows if an object exists in the object repository before using it. The doubt is usually whether there is a corresponding control in the AUT (Application Under Test).
If you really face the situation that sometimes the object is in the repository and sometimes it isn't (I can think of several ways for this to happen but none of them make much sense) then you can use VBScript's error handling mechanism.
On Error Resume Next ' Turn off error handling
' Just check if object is in repository, there's no need to do anything with it
Dim Exists: Exists=JavaWindow(className).JavaDialog(dialogName).Exist
If Err.Number <> 0 Then
doThisStuff 'Exists is still empty
Else
doThisStuffInstead ' Exists is properly set
End If
On Error Goto 0 ' Resume regular error handling
So, from the error you get, either the dialog that appears is different from the one you've stored in the repository or you don't have it there.
Have you checked it is really present in the Repository? You can try to just locate this element button.
Using the method of "if object not in the repository - skip the step" is not really a good idea. 1. Why would you want to skip the test/part of the test if the object was not saved in the repository?
2. If it's not there, so you need to make sure to store it.
I would assume that this "missing" object might have some values by which it's matched to the object from the repository different from test to test. You can tune the "matching" mechanism by manually setting the values by which you want QTP to locate it.

Resources