Monday, July 8, 2013

Working with Web Links

'***************************** Dynamic descriptive Programing **********************************
'***************************** Page Used: Google - Products*************************************
'**************To Count all the Links on Web Page and Display their Names with URL**************

'Launch Google - Products
Systemutil.Run "iexplore.exe","http://www.google.com/intl/en/about/products/"

'Descriptive object to identify  Browser  with a particular title
Set  Dbrowser=Description.Create
Dbrowser("micclass").Value="Browser"
Dbrowser("name").Value="Google - Products"

'Descriptive object to identify  Web page with a particular title
Set  Dpage=Description.Create
Dpage("micclass").Value="Page"
Dpage("title").Value= "Google - Products"

'Descriptive object to identify a  particular Link
Set  DLink=Description.Create
'DLink("micclass").Value="Link"
DLink("html tag").Value="A"

'wait till browser sync
Browser(Dbrowser).Page(Dpage).Sync

Set objLinkCount=Browser(Dbrowser).Page(Dpage).ChildObjects(DLink) 'Returnz the childobjects having 'Linkobject' description.
vrDLinkCount = objLinkCount.Count  'Returns number of links on webpage
MsgBox vrDLinkCount

For i=0 to vrDLinkCount-1
vrTag = objLinkCount(i).GetROProperty("name")
vrHREF = objLinkCount(i).GetROProperty("url")
msgbox vrTag & ": " &vrHREF
Next

'*=================Static descriptive Programing ================
'====================With HTMLTag  ==========================

Set ObjDes = Description.Create() 'Creates a new Empty Description Object
ObjDes("html tag").Value = "A" 'Adding Properties and Values to Descript Object

Systemutil.Run "iexplore.exe","http://www.google.com/intl/en/about/products/"

Set ChildObjCount = Browser("name:=Google - Products").Page("title:=Google - Products").ChildObjects (ObjDes) 'Gets the count of all Child Objects based on added description
NumCounts = ChildObjCount.Count() ' Gets the count of Descript values
Reporter.ReportEvent micPass, "The Number of Links on this page is", "Links Count = "&NumCounts ' Prints the Count of Links of the Page in Test Results
For i = 0 to NumCounts - 1 ' Making a For Loop to get all Similar Descript Values
Htag = ChildObjCount(i).GetROProperty("innertext") ' Gets the inner text of the value
Href =ChildObjCount(i).GetROProperty("href") 'Gets the Href of the inner text
Reporter.ReportEvent micPass, "The Name of the Link with URL", "Name: "& Htag&" and Url:" & Href ' reports the Tag and Href values to Test Results
Next


'*=================Static descriptive Programing ================
'==================== With MicClass ==========================

Systemutil.Run "iexplore.exe","http://www.google.com/intl/en/about/products/"

set linkobject=Description.Create 'This line is used to create description object
linkobject("Micclass").value="link" 'This line is used to identify the property.( In our case its link)
set linkcount=Browser("name:=Google - Products").Page("title:=Google - Products").ChildObjects(linkobject) 'This line is used to return the childobjects having 'Linkobject' description.
a= linkcount.Count  'This line is used get number of links on a webpage
MsgBox a

For i=0 to a-1
tag = linkcount(i).GetROProperty("name")
href = linkcount(i).GetROProperty("url")
msgbox tag & ": " &href
Next

'==============Dynmic  Descriptive Programing ===================
' To Count  Number of Links with a Particular Name on a Web Page
'=============================================================


SystemUtil.Run "iexplore", "http://youngistaancafe.blogspot.com/2013/07/student-registration-formhtml.html"

'Descriptive object to identify  Browser  with a particular title

Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"
oBrowser("name").Value = "Youngistaan Cafe: Student Registration Form.html"

Set oPage=Description.Create
oPage("micclass").Value="Page"
oPage("title").Value="Youngistaan Cafe: Student Registration Form.html"

Browser(oBrowser).Page(oPage).Sync

'Descriptive object to identify a  particular WebLink
Set oLink = Description.Create
oLink("micclass").Value = "Link"

Set oWebLinkCount = Browser(oBrowser).Page(oPage).ChildObjects(oLink)
vrCount = oWebLinkCount.Count

Counter = 0

'To Count the Number of Links with Name as "Home"

For i=0 to vrCount-1
vrLinkName = oWebLinkCount(i).GetROProperty("name")
       
If vrLinkName = "Home" Then
Counter = Counter +1
End If

Next

msgbox  "Number of lInks with name Home are: " &Counter

No comments:

Post a Comment