JavaEdit search function not locating visible element - vbscript

I've got two library functions:
Function searchWindow(title)
Set searchWindow = Window("title:=" + title)
End Function
And
Function searchField(label)
Set searchField = JavaEdit("attached text:=" + label)
End Function
Here I'm testing them:
Environment.Loadfromfile("C:\UFTConstants\constants.ini")
Set loginFrame = searchWindow(Environment.Value("frameLogin"))
loginFrame.Click
Set userField = searchField("User ID / Ci-Usager")
userField.Set "test"
The first function works fine, and it's title property matches that of the application. However, the second will not find the text field, despite properties matching:
The error:
I've tried other properties as well, tagname, various class properties, as well as combinations of all three, and none are producing a find.
Any ideas?
First Update
As per request, full spy screencap:
The full line generated by the recording tool:
JavaWindow("Application Name").JavaDialog("Window Title").JavaEdit("User ID / Ci-Usager").Set "user"
However, when I try to re-create this programmatically, I get the same error, only for JavaWindow instead:
"Cannot identify the object [JavaWindow] of (class JavaWindow)..."
Possible Java set-up issue? This would not explain why recording can still locate Java objects, however.
Second Update
Here are the recognition properties:
I have ensured that all properties are set, still unable to locate.
Final Update
Ok, I've reduced the code to absolute barebones. No external constant file, no external library calls. I've copied the full extent of what is recorded in recording mode. I've printed each variable to ensure accuracy. I've included the full object hierarchy:
Set objWin = JavaWindow("label:=<redacted>")
objWin.SetTOProperty "to_class", "JavaWindow"
objWin.SetTOProperty "toolkit class", "javax.swing.JFrame"
MsgBox objWin.GetTOProperty("label")
MsgBox objWin.GetTOProperty("to_class")
MsgBox objWin.GetTOProperty("toolkit class")
Set objDialog = objWin.JavaDialog("label:=<redacted>")
objDialog.SetTOProperty "to_class", "JavaDialog"
objDialog.SetTOProperty "toolkit class", "<redacted>.LoginDialog"
MsgBox objDialog.GetTOProperty("label")
MsgBox objDialog.GetTOProperty("to_class")
MsgBox objDialog.GetTOProperty("toolkit class")
Set objEdit = objDialog.JavaEdit("attached text:=User ID / Ci-Usager")
objEdit.SetTOProperty "to_class", "JavaEdit"
objEdit.SetTOProperty "toolkit class", "javax.swing.JTextField"
MsgBox objEdit.GetTOProperty("attached text")
MsgBox objEdit.GetTOProperty("to_class")
MsgBox objEdit.GetTOProperty("toolkit class")
objEdit.Set "test"
Note the redacted text is to remove identifying elements from the code. They have been triple-checked on my side and are correct.
This still does not work.
However, recording the same does. What gives?

I think you have to mention the full hierarchy while working with the Javaedit field. Try re-writing the code for the function searchField as :
Function searchField(label)
Dim objFrame
Set objFrame = searchWindow(Environment.Value("frameLogin"))
Set searchField = objFrame.JavaEdit("attached text:=" + label) 'Javaedit should be the child of the login window. You had to mention the full hierarchy here
End Function

Related

How to create description object model at runtime in uft/qtp?

thank you for taking a look on this question. Just wondering if there is a best approach to create description object model at runtime. My code fails
Object doesn't support this property or method: 'Browser(...).page(...).WebButton'
FunctionCreateDescObjAt_RunTime(StrBrowserNme,StrBrwsrTitle,StrObject,StrPgeNme,StrPgtitle,StrObjectName,index)`
'create a description object for Browser & Page`
Set WebBrwsrDesc= Description.Create
WebBrwsrDesc("application version").value= "Internet Explorer.*"
If StrBrowser<>"" Then
WebBrwsrDesc("name").value=StrBrowserNme
WebBrwsrDesc("title").value=StrBrwsrTitle
End If
Set WebPageDesc= Description.Create
WebPageDesc("name").value=StrPgeNme
WebPageDesc("title").value=StrPgtitle
' 'Based on the type of object, execute the condition`
Select Case StrObject`
Case "WebButton"
Set WebBtnDes= Description.Create
WebBtnDes("html tag").value="INPUT"
WebBtnDes("name").value=StrObjectName
WebBtnDes("micclass").value="button"
WebBtnDes("index").value=index
'Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick
Browser(WebBrwsrDesc).page(WebPageDesc).WebButton(WebBtnDes).click
end select
End Function
I am making a call from action
CreateDescObjAt_RunTime "Account Login","Your Store", "WebButton", "", "Account Login", "Login", "" And this is failing. However if I un comment this line & comment problem line, it works
Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick
Could you please help me with the right approach? thanks
If you want to set a generic browser and page you can simply use a statement similar to the line you have commented:
Dim objPage : Set objPage = Browser("class:=browser").Page("title:=.*")
The line above will create a page object that you can work with.
Check the parameters being passed to your function to make sure you are correctly identifying your browser and page.
For the part of your actual object, which you want to create at runtime, you need to create a Description object, then look for the ChildObjects of your main object (in this case, your page) and store it to a collection. After that you can check whether or not your object is found. So your Select Case part would be something like this:
Select Case StrObject
Case "WebButton"
' This is just a description of your object, not your actual object
Dim descButton : Set descButton = Description.Create
descButton("html tag").value="INPUT"
descButton("name").value=StrObjectName
descButton("micclass").value="button"
descButton("index").value=index
' In the following statement you are looking for all child objects
' of your page that matches with your description, and storing it
' into the collButton collection
Dim collButton : Set collButton = Browser("class:=browser").Page("title:=.*").ChildObjects(descButton)
If collButton.count > 0 Then ' Now you are checking if any object was found
' There are many ways to get the button object that you want.
' Here I'm just assuming you want the first one, but you could iterate
' into the collection to make sure you have the right one
Dim objButton : Set objButton = collButton(0) ' I'm getting the first item, which is in index 0 of your collection
objButton(0).Click ' This object already have the whole Browser().Page().WebButton() identified, so no need to use it
Else
MsgBox "No WebButton found. Please check your Description object"
End If
' Your other cases...
End Select
MicClass of a Webbutton Can't be button. It should be WebButton
' You are using following
WebBtnDes("micclass").value="button"
It Should be : WebButton
'Anyway Describing Description Object
Set ObjButton=Description.Create
ObjButton("MiCClass").value="WebButton"
ObjButton("name").value=strButtonName
ObjButton("htmlid").value=strHtmlId
Set ObjButton= Browser().page().ChildObject(ObjButton)

visual relation Identifier in QTP

i am using visual relation Identifier in QTP for setting a value in webedit.Here is my code
Set rc = VisualRelations.Create
Set relation = rc.Add
relation.relatedobjectpath = "Browser(""ABC"").Page(""XYZ"").WebElement(""innertext:=E-Mail ID"")"
relation.relativeposition = micRelLeft
relation.setargument micrelinline, True
Set des=Description.Create
des.Add "micclass","WebEdit"
des.Add "visual relations",rc
Browser("ABC").Page("XYZ").WebEdit(des).set "qtpuser#abc.com"
Set relation = Nothing
Set rc = Nothing
The problem is when i use description programming for webElement in Line 3 the QTP showing an error message "Cannot find "webedit" objects parent". But, when i store webelement "E-Mail id" in OR, the code is working fine without any error.
Can u please tell me what can i do in this case to resolve the issue.
Thanks in Advance:)
There seems to be a limitation in QTP that the anchor test object in VRI must be in the object repository.
Thankfully there is a workaround, you can create a dummy anchor test object in the OR with a description of a blank innertext (by using the Define New Test Object button).
Then use SetTOProperty to get the dynamic behaviour you can achieve with descriptive programming.
Set rc = VisualRelations.Create
Set relation = rc.Add
Browser("ABC").Page("XYZ").WebElement("Anchor").SetTOProperty "innertext", "E-Mail ID"
relation.relatedobjectpath = "Browser(""ABC"").Page(""XYZ"").WebElement(""Anchor"")"
relation.relativeposition = micRelLeft
relation.setargument micrelinline, True
Set des=Description.Create
des.Add "micclass","WebEdit"
des.Add "visual relations",rc
Browser("ABC").Page("XYZ").WebEdit(des).set "qtpuser#abc.com"
Set relation = Nothing
Set rc = Nothing
When you store the WebElement "E-Mail id" in OR, its parent Page(""XYZ"") will also be stored into OR.
The problem is that OR way is used to identify Page, but the DP way is used to identify the WebElement. If you delete the WebElement "E-Mail id" but remain the Page("XYZ"), the script should work well.

Run time error 1004, Application defined or object defined error in excel vbs

I have written vbscript code to add chart in page 1 of excel for which the source is from other sheet of same excel which name is "CL.1.1" but i am getting the above error can any one help what was wrong in my below code.
Sub DispvsTime(Shname)
Sheets("Sheet1").Select
noofsheets = ActiveSheet.ChartObjects.Count
If noofsheets > 0 Then
ActiveSheet.ChartObjects.Select
ActiveSheet.ChartObjects.Delete
End If
Sheets("Sheet1").Pictures.Visible = False
ActiveSheet.Shapes.AddChart(1000, 420, 50, 500).Select
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=Sheets(Shname).Range("G2:H2001")
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Text = "Displacement VS Time"
End Sub
here shname is name of the sheet where data is picked.
Can any one help me to find out the bug inside the code to get this error ?
If the sheet name is Shname then place it around quotation marks, if it is a variable name, which holds the sheet name, then ignore this post :P
Sheets("Shname")
If your code is really VBScript as you say, and not VBA as it looks like, then there are several issues:
Unlike VBA you cannot use objects like ActiveSheet or ActiveChart directly in VBScript. You need a reference to these objects, usually the application object:
Set xl = CreateObject("Excel.Application")
xl.ActiveSheet.Name = "foo"
VBScript doesn't know about Excel/Office constants like xlXYScatterSmoothNoMarkers or msoElementChartTitleAboveChart, so you have to either use literal values or define those constants yourself:
Const xlXYScatterSmoothNoMarkers = 73
You can't use named arguments like Source:=... in VBScript:
xl.ActiveChart.SetSourceData xl.Sheets(Shname).Range("G2:H2001")
See here for a more detailed explanation of the differences between VBA and VBScript.

Web Page not updated when value is selected from web list using QTP

So I have been searching for an answer for this for a long time, and have come up with a temporary solution which i'll write below, but I was wondering if theres a more elegant one?
In the application im working on there is a weblist which can contain one of four values which are: 10,25,50,100. When a value is selected the web table below should show 10,25,50 or 100 results depending on the value selected of course.
Now when I call the standard Obj.Select "100" for example it changes the list box to 100 but nothing else happens. No event is triggered so the web table below remains the same. If I manually select 100 the web table updates to display 100 records.
I tried firing different events to the web list but none of them seemed to update the web table!
In the end I settled on the solution below:
Public Function CustomSelect(obj, strValue)
Dim intCounter, strProperty, boolItemInList, strEnabledOrDisabled, arrAllItems, strAllItems
Dim xCoord, yCoord
If strValue = "##" Then
Call AddComment("Passed in ##, skipping set function")
Exit Function
End If
Reporter.Filter = rfEnableErrorsOnly
strProperty= obj.GetTOProperty("name")
If strProperty= "" Then
strProperty= obj.GetTOProperty("html id")
End If
Reporter.Filter = rfEnableAll
If obj.exist(5) Then
XCoord = obj.GetROProperty("abs_x")
YCoord = obj.GetROProperty("abs_y")
strEnabledOrDisabled = obj.GetROProperty("disabled")
If strEnabledOrDisabled = 0 Or strEnabledOrDisabled = "0" Then
strAllItems = obj.GetROProperty("all items")
arrAllItems = split(strAllItems,";")
For intCounter = LBound(arrAllItems) to Ubound(arrAllItems)
'Obj.SendKeys "{DOWN}"
Obj.Select "#" & intCounter
If arrAllItems(intCounter) = strValue Then
Exit For
End If
Next
Else
Call ReportExpectedVsActual("Weblist is disabled: " & strProperty, False, True)
End If
Else
Call ReportExpectedVsActual("Weblist doesnt exist: " & strProperty, True, False)
End If
End Function
RegisterUserFunc "WebList", "CustomSelect", "CustomSelect"
I know it looks a bit messy but its all I can think of to get it working at the moment. Does anyone have any other ideas of what to try?
Cheers
Nick
There are at least two things to try:
Try to look into the source of the webpage to see how an action is triggered. It could be something like onchange='RefreshIt();' or you'll see an EventHandler attached to it, then you have to dig somewhat deeper.
If you have indentified the event that will update your page, try firing that event after updating the list with WebListObject.FireEvent {yourEvent}. yourEvent could be a string containing onchange, onclick, ondblclick, onblur, onfocus, onmousedown, onmouseup, onmouseover, onmouseout, onsubmit, onreset or onpropertychange.
Another way that is even simpler (but giving you less control) is worth a try. This is done through the settings: Go to Tools > Options and in the tree view, select Web > Advanced. Try what happens when changing the checkbox for Run only click and the radiobuttons for Replay type.

ArcPad - VBscript - Autopopulate attributes

I am using the following script to grab parcel and address information from one layer to fill the attribute table of a newly created feature.
There is no returned error, but the problem I am having is that there seems to be the wrong information stuck in the memory of recordselect function. No matter where I place a point it gives the same parcel # and address. Or maybe it isn’t actually be performing the IF function properly.
Sub Address
Dim rsCurrentXY
Set rsCurrentXY = Map.Layers("Violations").records
rsCurrentXY.movelast
Dim objXYShape
Set objXYShape = rsCurrentXY.Fields.Shape
Dim pControls
Set pControls= Application.Map.selectionlayer.Forms("EDITFORM").Pages(“PAGE1”).Controls
Dim rsGrid
' Find corresponding map page to the valve point
Set rsGrid = Map.Layers("ACPA_parcels").records
rsGrid.movefirst
Do While Not rsGrid.eof
If rsGrid.fields.shape.Ispointin(objXYShape) Then
pControls("txtAddress").value = rsGrid.Fields("ADD1").Value
Exit Do
End If
rsGrid.Movenext
Loop
' Clean Up
Set rsCurrentXY = Nothing
Set objXYShape = Nothing
Set rsGrid = Nothing
End Sub
(I have another subroutine called "PIN" that would do the exact same thing.)
I have them called when their respective edit boxes in the custom form are activated by the inspector.
Thanks for the help,
Robert
Accessing the EDITFORM via Application.Map.selectionlayer.Forms("EDITFORM") will be problematic. Whenever working with controls on an EDITFORM you should using ThisEvent.Object to discover all your objects. For example, if your event handler is Page_OnLoad then ThisEvent.Object will refer to your current page. You should have code like this:
Dim pPage1
Set pPage1 = ThisEvent.Object
Dim pControls
Set pControls = pPage1.Controls

Resources