Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New attribute property keywords 1822 #1850

Merged
Merged
49 changes: 49 additions & 0 deletions atest/acceptance/keywords/elements.robot
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,55 @@ Get Element Attribute
${class}= Get Element Attribute ${second_div} class
Should Be Equal ${class} Second Class

Get DOM Attribute
${id}= Get DOM Attribute link:Link with id id
Should Be Equal ${id} some_id
# Test custom attribute
${existing_custom_attr}= Get DOM Attribute id:emptyDiv data-id
Should Be Equal ${existing_custom_attr} my_id
${doesnotexist_custom_attr}= Get DOM Attribute id:emptyDiv data-doesnotexist
emanlove marked this conversation as resolved.
Show resolved Hide resolved
Should Be Equal ${doesnotexist_custom_attr} ${None}
# ToDo:
# Ref: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

Get non existing DOM Attribute
${class}= Get DOM Attribute link:Link with id class
Should Be Equal ${class} ${NONE}

More DOM Attributes
[Setup] Go To Page "forms/enabled_disabled_fields_form.html"
# Test get empty attribute
${disabled}= Get DOM Attribute css:input[name="disabled_input"] disabled
Should Be Equal ${disabled} true # ${True}
emanlove marked this conversation as resolved.
Show resolved Hide resolved
${disabled}= Get DOM Attribute css:input[name="disabled_password"] disabled
Should Be Equal ${disabled} true # disabled
emanlove marked this conversation as resolved.
Show resolved Hide resolved
# Test empty string as the value for the attribute
${empty_value}= Get DOM Attribute css:input[name="disabled_password"] value
Should Be Equal ${empty_value} ${EMPTY}
${disabled}= Get DOM Attribute css:input[name="enabled_password"] disabled
Should Be Equal ${disabled} ${NONE} # false
emanlove marked this conversation as resolved.
Show resolved Hide resolved

Get Property
[Setup] Go To Page "forms/enabled_disabled_fields_form.html"
# ${attributes}= Get Property css:input[name="readonly_empty"] attributes
${tagName_prop}= Get Property css:input[name="readonly_empty"] tagName
Should Be Equal ${tagName_prop} INPUT
# Get a boolean property
${isConnected}= Get Property css:input[name="readonly_empty"] isConnected
Should Be Equal ${isConnected} ${True}

# ToDo: nned to test own versus inherited property
# ToDo: Test enumerated property
# Test proprty which returns webelement
${children}= Get Property id:table1 children


Get "Attribute" That Is Both An DOM Attribute and Property
emanlove marked this conversation as resolved.
Show resolved Hide resolved
[Setup] Go To Page "forms/enabled_disabled_fields_form.html"
${value_property}= Get Property css:input[name="readonly_empty"] value
${value_attribute}= Get DOM Attribute css:input[name="readonly_empty"] value
Should Be Equal ${value_property} ${value_attribute}

Get Element Attribute Value Should Be Should Be Succesfull
Element Attribute Value Should Be link=Absolute external link href http://www.google.com/
Element Attribute Value Should Be link=Absolute external link nothere ${None}
Expand Down
31 changes: 31 additions & 0 deletions src/SeleniumLibrary/keywords/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,37 @@ def get_element_attribute(
"""
return self.find_element(locator).get_attribute(attribute)

@keyword
def get_dom_attribute(
self, locator: Union[WebElement, str], attribute: str
) -> str:
"""Returns the value of ``attribute`` from the element ``locator``. `Get DOM Attribute` keyword
only returns attributes declared within the element's HTML markup.
emanlove marked this conversation as resolved.
Show resolved Hide resolved

See the `Locating elements` section for details about the locator
syntax.

Example:
| ${id}= | `Get DOM Attribute` | css:h1 | id |

"""
return self.find_element(locator).get_dom_attribute(attribute)

@keyword
def get_property(
self, locator: Union[WebElement, str], property: str
) -> str:
"""Returns the value of ``property`` from the element ``locator``.

See the `Locating elements` section for details about the locator
syntax.

Example:
| ${text_length}= | `Get Property` | css:h1 | text_length |

"""
return self.find_element(locator).get_property(property)

@keyword
def element_attribute_value_should_be(
self,
Expand Down