Monday, 5 January 2015

color of the link changes when hovered on that link, how do you get that changed color?

To do this you need to switch QTP replay mode to Mouse replay mode, fire an OnMouseOver event, get the color of the object using current style method, and then switch back the QTP reply mode Event Replay mode. Please look at the following code:

Dim oColor, oColorMouseOver

oColor=Browser("CNN.com - Breaking News,").Page("CNN.com - Breaking News,").Link("How journalist won over").Object.currentStyle.color

Setting.WebPackage("ReplayType") = 2

Browser("CNN.com - Breaking News,").Page("CNN.com - Breaking News,").Link("How journalist won over").FireEvent "onMouseOver"

oColorMouseOver=Browser("CNN.com - Breaking News,").Page("CNN.com - Breaking News,").Link("How journalist won over").Object.currentStyle.color

Setting.WebPackage("ReplayType") = 1

msgbox "Color of the object is: " & oColor & ". And the Color of the object on MoouseOver is: " & oColorMouseOver

 

You can also use this CurrentStyle Object method to get the FontSize, FontStyle, BackGroundColor etc., in the following way:

oFontSize= Browser("BrowserName").Page("PageName").Link("LinkName").Object.currentStyle.fontSize
oFontStyle= Browser("BrowserName").Page("PageName").Link("LinkName").Object.currentStyle.fontStyle
oBackGroundColor= Browser("BrowserName").Page("PageName").Link("LinkName").Object.currentStyle.backgroundcolor

No comments:

Post a Comment