Sample code to click on dynamic link using Browser DOM
By Navneesh Garg
Let us try to understand a practical scenario. You have webpage. On this web-page the total number of links changes dynamically. Also the links on this webpage are not static links and are created dynamically based on inputs on the previous page. User needs to click on a link with a particular title on this page.
There can be multiple solutions to this problem. Please find below the solution which uses Document Object Model of Browser to browse through the links and click on the specified link.
Solution:
1. User uses DOM of Browser to get reference to the webpage
2. User get reference to collection of links on the webpage
3. Use for Loop to get to each link and based on the required property match click on the required link
Sample Code
************************************************************************
Function (Expected_Title)
Set obj = Browser(”Simple Validation”).Page(”Simple Validation”).Object.body.document
set Linkcollections= obj.Links
msgbox “No. of Links is” & Linkcollections.Length
dim counter
counter=0
For each Element in Linkcollections
StrTitle = Element.GetROProperty (“title”)
If StrTitle = Expected_Title then
Element.Click
Exit For
Else
Counter = Counter + 1
End If
Next
End Function
************************************************************************
Another Possible solution could be to use Description Object to get reference to all objects in the page.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
http://www.qacampus.com
http://www.crestech.in
http://www.crestechsoftware.com.au
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment