Forum Discussion
6 Replies
- tobelloContributorHi there,
I had the same issue this week wth a keyword not able to select a DropDownListBox item and I came up with a little code of mine to resolve (kind of an utilility function). Enjoy and update it to fit your need.
By the way, anyone to make it better is welcome to do so...
'@Function FindDropDownListBox to find a Drop-Down ListBox and select a value within it.
'@@Param1: String; Object to find's property Name.
'@@Param2: String; Object to find property content/caption Value.
'@@Param3: Interger; Deepness of search in TC mapped tree.
'@@Param4: Boolean; Mapped tree to be refresh for search.
'@@Param5: String Or Integer; Value to select as the choice.
'@@Return: Returns a dropdownListBox with selected value OR log error message if searched object or value to select was not found.
Sub FindDropDownListBox(propN, propValKey, strVal)
Dim browser
Dim page
Dim ddListBox
Set browser = Aliases.browser
Set page = browser.Page("*")
Set ddListBox = page.NativeWebObject.Find(propN,propValKey)
If ddListBox.Exists Then
Call ddListBox.focus()
diff = aqString.Find(ddListBox.wItemList, strVal, 0, false)
If diff <> -1 Then
ddListBox.ClickItem strVal
page.Wait 1
Else
Log.Error "Search Error: DropDown List '" & propValKey & "' searched by the property '" & propN & "' was find but Item '" & strVal & "' to select was not found."
End If
Else
Log.Error "Search Error: DropDown List '" & propValKey & "' searched by the property '" & propN & "' was not find."
End If
End Sub
Once you call this utility in you script or keyword tests, just provide it with the property name you want TC to search for and the value that distinguish this object from other ones among the mapped DropdownListBoxes...
Regards,
TedB - kpinnisettiContributorHi Ted,
Thanks for your response. Our application is developed in asp.net, and they used microsoft controls ,web forms. In my current project properties i don't have Web form for microsoft control. May be that's why that method is not available for the objects in the application.
Do you have any idea about how to add web form to my current project.
Thanks. - tobelloContributor
Hi there,
I'm a new (like a month or so) to TC but that was my ways of resolving the issues.
For your asking, I,ve also implementeed some of my routine by changing the page call to a form call. Thus instead of this
Set browser = Aliases.browser
Set page = browser.Page("*")
I use this:
[some code line hier]
Dim form
Set form = Aliases.browser.{nameOfTheApplicationPage}.formAspnetform
Set myObjectToFind = form.FindChild("IdStr",...
[some code line hier]
So the purpose is to get the form representing the page and then I can look for the DropdownListBox object on wich I could call the ClickItem method..
Try it and let us know if this worked fined for yo or not... Otherwise other Community members could try to pop out some other stuff or redirect both of us to another solution
Regards, - kpinnisettiContributor
Hi Ted,
I used the following code reference to your code. But still that method is not found.
Sub Test
Set Dept = Aliases.PayPlanDeptDD
Dept.Click
Set obj = Aliases.panelSelect2Drop
Set objtofind = obj.FindChild("Name","*select2_drop*")
objtofind.clickitem("Admin")
End Sub
error - You are trying to call the "clickitem" method or property of an object that does not exist.. - tobelloContributor
Hi,
You code does not explain what your are trying to do...
Anyway, you have to make sure TC does understand where it is located in its processing in order to complete actions to execute otherwise you'll always get errors:
In your code the 'Aliases' referes to what, a page a form?
but my point of view is this:
As it's a web application (posting and receiving page aka forms) you have to:
obtain the page object(1) in first and get the focus to it (2) and look for the objectToFind(3) and get its focus (4) And perform the action(5):
(1) Set browser = Aliases.browser
(2) Set page = browser.Page("*") '* Is for the current page in focus instead of navigating to a specific page using session And/or cookies parameters...
(3) Set ddListBox = page.NativeWebObject.Find(propN,propValKey)
(4) Call ddListBox.focus()
(5) ddListBox.ClickItem strVal
If you want to process using a form make sure TC understand what you are looking to use as objectSSSS:
The form is related to the page mapped when recording your test or the one (page) mapped manually.
You can use the spy to get the form associated to the page and ask TC to show it in the object browser.
In the Object browser of you project, you will find the mapped browser with the associate application(web page/application address) with its ASP form.
(Refer to TC documentation on 'Mapping' subject to see how it works)
So after you get the ref to the form of the application page, then you can set its focus on and then search for the dropDownListBox you are looking for.
Set form = Aliases.browser.{nameOfTheApplicationPage}.{nameOfTheAspNetFormReferencingThePage}
Hope all this help...
Regards,
- kpinnisettiContributorReally thanks for your reply.
The code can recognize the objects i mentioned and test ran successfully....it worked fine..the problem is ,when i spy on the object, it did'nt have clickItem method, so that i can't perform that action to click on specific item i mentioned.
In our application they are using HTML select Dropdown which is not recognized, i submitted a ticket to support team, may be i can install that extension to my object mapping.
So i'm using Keys method (work around) to click on that item.
Thanks.