robotframework / SeleniumLibrary

Web testing library for Robot Framework
Apache License 2.0
1.36k stars 751 forks source link

Add keywords to fetch differentiated element Attribute or Property #1822

Closed emanlove closed 6 months ago

emanlove commented 1 year ago

Selenium 4 add the capabilities to get the element's actual property or attribute based upon the value found within the DOM. These differ from the previous implementation which could get either based upon the context.

References:

get_dom_attribute method get_property method Selenium 4 - Element Attribute and Property Methods

emanlove commented 1 year ago

Some of my initial notes on Element Attributes and Properties

Questions either worth asking or expected from end users

emanlove commented 1 year ago

I ask over on the Selenium Slack channel about the difference between an attribute and a property, asking

... is there a good definition of what is/should be an attribute versus a property? For attribute my initial assumption would be it is the Element Content Attribute (as defined in the w3c html spec). Properties seem to be .. well, not sure how to say it .. a browser specific value??

Jim Evans, a Selenium core developer, responded with

Generally speaking, in the W3C world, attributes are actual attributes in the HTML markup, and properties are properties that are part of the EcmaScript Interface Description Language (IDL) of the object. The properties are just as standardized as the attributes (see MDN for proof). Often, properties and attributes overlap, but sometimes they don't. Most people don't understand the difference between attributes and properties, and never need to care, so Selenium (possibly confusingly) uses the generic term "attribute" to refer to "some characteristic of an element that might be represented by a JavaScript property, but also might be an attribute set in the HTML markup." The W3C working group, wanting to be more precise, created two different end points for the different specific meanings.

This reinforces my idea that one can get a list of DOM attributes from the HTML spec; in particular Section 4 Sematics which covers all the elements. These are attributes one sees when looking at the DOM. It should be noted that not all attribute are visible but still have a "value".

The properties of an element are also documented. For example an HTML Element will have these properties. Properties can be seen by through Chrome's DevTools. Or they can be inquire through the Console tab within Chrome using dir method. For example, under the Checkboxes page of The-Internet we could query the properties (and methods) of the input checkbox element using console.dir($('#checkboxes input')[0]).

emanlove commented 6 months ago

Fixed in #1850