简体   繁体   English

UFT / QTP:无法在Firefox中访问Object.CurrentStyle

[英]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 . 我正在使用以下代码在IE上获取“链接”的字体大小。

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

However, if I use the same code on FireFox , QTP/UFT throws error: 但是,如果我在FireFox上使用相同的代码,则QTP / UFT会引发错误:

object required "Object.CurrentStyle". 对象为必需的“ 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 研究和探索了很多之后,我发现,Firefox浏览器不Object.CurrentStyle ,但它是Object.Style这是QTP的内置功能,下面的代码使用

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

but I'm not fetching the results for the firefox 但我没有获取Firefox的结果

I had similar issues when switching between browsers. 在浏览器之间切换时,我遇到了类似的问题。 IE has a special style object that is not supported in other browsers. IE具有其他浏览器不支持的特殊样式对象。 I suggest a more generic tactic, treat style for what it is - an html attribute. 我建议一种更通用的策略,将其视为样式-html属性。 You could go pure DOM, but lets use the UFT test objects: 您可以使用纯DOM,但可以使用UFT测试对象:

Step 1: find the html node you want to extract style from: 步骤1:找到您要从中提取样式的html节点:
Set element = Browser("creationtime:=0").Page("title:=HelloWorld").WebElement("xpath:=//html/body/div[@id='something']")

Step 2: extract the style data 步骤2:提取样式数据
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 attributeValue现在是一个包含样式属性数据的字符串,可以将其拆分,进行正则表达式或您需要的任何内容

`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. 只能在IE上运行而不能在FireFox上运行 ,我们可能会选择使用“ Style”代替FireFox的“ currentStyle”,但这不能正常工作。 Also the FontSize is read as "FontSize" in IE and "font-size" in Firefox 另外, FontSize在IE中读为“ FontSize”, 在Firefox中 读为 “ font-size”

To retrieve the required information form the application on Firefox 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. FireFox DOM不支持与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 . 您可以在此处找到FireFox页面/文档DOM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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