Monday, November 30, 2009

Check if a particuar text is present on page or not.

In few of scenarios we have to check that text is present on a page or not.

The following function will return True in case if text exists else function will return False.

'Create Page object
set objpage = Browser(“Browser Prop”).Page(“Page Prop”)

'Calling the function
msgbox VerifyTextOnPage(objParent ,”Test” )

Function VerifyTextOnPage(byval objpage , byval Textvalue )
On error resume next
Set oDesc= Description.Create()
oDesc(“micclass”).value=”WebElement”
oDesc(“html tag”).value=”.*[A-Za-z0-9].*”
oDesc(“outertext”).value =”.*[A-Za-z0-9].*”

'Create ALL child object
set collItems= objpage.ChildObjects(oDesc)

'Get all text from web page and store in a variable

For i=1 to collItems.count
OutPutText= OutPutText & collItems.Item(i).GetROProperty(“outertext”)
Next

'compare the text

If instr(1,lcase(OutPutText),lcase(Textvalue)) > 0 Then

' return true if found

VerifyTextOnPage= True
Else
rem return true if not found
VerifyTextOnPage= False
End If
On Error GoTo 0
End Function

Tuesday, November 24, 2009

Get Mouse Over Color of a Link

Using ReplayType setting to Mouse Events while firing an onMouseOver event on the link.

You will see that the hover event is triggered with the ReplayType set to Mouse Events:

Setting.WebPackage("ReplayType") = 2
Browser("xyz").page("xyz").Link("xyz").FireEvent "onMouseOver"
MsgBox Browser("xyz").page("xyz").Link("xyz").Object.currentStyle.color
Setting.WebPackage("ReplayType") = 1


Or

Function GetoverColor(oLink)
Setting.WebPackage("ReplayType") = 2
oLink.FireEvent "onMouseOver"
GetoverColor = oLink.Object.currentStyle.color
Setting.WebPackage("ReplayType") = 1
End Function