简体   繁体   中英

UFT / QTP : unable to access Object.CurrentStyle in Firefox

I am using the below code for fetching the font size of a "link" on IE .

Browser("BB").Page("PP").Link("link").Object.CurrentStyle.fontSize

However, if I use the same code on FireFox , QTP/UFT throws error:

object required "Object.CurrentStyle".

After alot of research and exploration I found that for FireFox it is not Object.CurrentStyle , but it is Object.Style which is an inbuilt function in QTP, and used below code

Browser("BB").Page("PP").Link("link").Object.style.fontSize

but I'm not fetching the results for the firefox

I had similar issues when switching between browsers. IE has a special style object that is not supported in other browsers. I suggest a more generic tactic, treat style for what it is - an html attribute. You could go pure DOM, but lets use the UFT test objects:

Step 1: find the html node you want to extract style from:
Set element = Browser("creationtime:=0").Page("title:=HelloWorld").WebElement("xpath:=//html/body/div[@id='something']")

Step 2: extract the style data
attributeValue = element.Object.GetAttribute("style")

attributeValue is now a string containing the style attribute data, it can be split, RegExp'd or what ever you need

`TestObject.Object.currentStyle.fontSize` 

will work only on IE not on FireFox , we may get the option to use "Style" in place of "currentStyle" for FireFox but that doesn't work properly. Also the FontSize is read as "FontSize" in IE and "font-size" in Firefox

To retrieve the required information form the application on Firefox

set FXObj= Browser("title:=Test_2").Page("title:=Test_2").Link("text:=link")

Set webElem = FXObj.Object
Set compStyle=Browser("title:=Test_2").Page("title:=Test_2").Object.defaultView.getComputedStyle(webElem, "")

fntsize = CompStyle.getPropertyValue("font-size")
Print fntsize

The FireFox DOM does not support all of the same methods as IE. I've solved similar problems of cross-platform testing by getting the "application version" property of the browser and using a function to determine the values I'm looking for based on the browser type.

It's not glamorous but it's saved a lot of heads for my team.

You can find the FireFox page/document DOM here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM