Forum Discussion
ArtemS
Alumni
15 years agoHello,
The way to retrieve CSS attributes of a web element depends on the following two factors:
a) whether the page is displayed in Microsoft Internet Explorer or in Mozilla Firefox;
b) whether the attributes are applied directly to the element or inherited from the element's parents.
To access the set of an element's immediate CSS attributes, use the element.style property. (E.g. myLink.style.display)
To get the resulting CSS attributes of the element (taking into account the attributes applied to parent elements), use the element.currentStyle property. (E.g. myLink.currentStyle.display). Both properties return the IHTMLStyle objects.
To obtain the set of an element's immediate CSS attributes, use the element.style property. It returns the CSSStyleDeclaration object. Despite that the returned objects are different, the script syntax will be the same as for IE: myLink.style.display.
The technique of getting the resulting CSS attributes in Mozilla browsers is a little bit more complicated. The resulting style is returned by the window.getComputedStyle method which accepts the needed element as a parameter.
Best regards, Artem.
The way to retrieve CSS attributes of a web element depends on the following two factors:
a) whether the page is displayed in Microsoft Internet Explorer or in Mozilla Firefox;
b) whether the attributes are applied directly to the element or inherited from the element's parents.
- For the Microsoft engine:
To access the set of an element's immediate CSS attributes, use the element.style property. (E.g. myLink.style.display)
To get the resulting CSS attributes of the element (taking into account the attributes applied to parent elements), use the element.currentStyle property. (E.g. myLink.currentStyle.display). Both properties return the IHTMLStyle objects.
- For the Mozilla engine:
To obtain the set of an element's immediate CSS attributes, use the element.style property. It returns the CSSStyleDeclaration object. Despite that the returned objects are different, the script syntax will be the same as for IE: myLink.style.display.
The technique of getting the resulting CSS attributes in Mozilla browsers is a little bit more complicated. The resulting style is returned by the window.getComputedStyle method which accepts the needed element as a parameter.
...
var element, ComputedStyle;
if (Options.Web.TreeModel == "DOM")
{
//Obtain the element in the DOM model
element = page.document.getElementById(elementID);
}
else
{
//Obtain the element in the Tag, Tree and Hybrid models
element = page.contentDocument.getElementById(elementID);
}
ComputedStyle = page.content.getComputedStyle(element, "");
Log.Message("The value of the display attribute is: "+ComputedStyle.display);
}
Best regards, Artem.