Micro Focus QTP (UFT) Forums
Selecting a WebElement from a List of Web Elements - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Selecting a WebElement from a List of Web Elements (/Thread-Selecting-a-WebElement-from-a-List-of-Web-Elements)



Selecting a WebElement from a List of Web Elements - chrispraveen - 02-21-2012

Hi All,
I am working on a scenario, where I need to select a particular item from a list of items in a Window. The I have written is below:

Code:
'Initializing a Flag
Valid=False
Set objShell=CreateObject("WScript.Shell")
'Looping the statement
Do Until Valid=True
'Itemname is the name of the WebElement I need to select
If(Brw(X).Pg(X).WebElement("html tag:=TD","innertext:="itemname,"outertext:="itemname,"index:=1").Exist (2))Then
Brw(X).Pg(X).WebElement("html tag:=TD","innertext:="itemname,"outertext:="itemname,"index:=1").Click
'The below statement will add the selected Item to the "Selected Items panel"
Brw(X).Pg(X).WebElement("class:=bi-button button.*","innertext:=>>","index:=1").Click
Valid=True
Else
'Here the Page down button will be pressed if the WebElement is not found in the visible.Just like a Scroll Down
objShell.SendKeys "{PGDN}"
Valid=False
Loop

The problem I face with the above code is that some times the incorrect item gets selected to the "Selected items window". If I dont use index I get "Object description matches more than one WebElement" error.

The incorrect item that gets selected is always just above or below the correct one. Most of the times code works properly, sometimes I got wrong things selected. eg: I need to select 'Delete' item whose innertext value is 'Delete'.

Delete a value
Delete
Delte by name

The aboce code selects, "Delete a value" or "Delete by name" instead of 'Delete' from the list.

Note: No html id available. Im working on a Web application that runs in IE8.

I hope someone could help me in fixing the codes


RE: Selecting a WebElement from a List of Web Elements - chrispraveen - 02-22-2012

Just changed the order for selecing the items... It works fine..Very Wiered...