Skip to content

Commit 87ba93f

Browse files
committed
py: Expand WebElement.get_attribute API docs
1 parent 1023f55 commit 87ba93f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

py/selenium/webdriver/remote/webelement.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,23 @@ def clear(self):
7373
self._execute(Command.CLEAR_ELEMENT)
7474

7575
def get_attribute(self, name):
76-
"""Gets the attribute value.
76+
"""Gets the given attribute or property of the element.
77+
78+
This method will return the value of the given property if this is set,
79+
otherwise it returns the value of the attribute with the same name if
80+
that exists, or None.
81+
82+
Values which are considered truthy, that is equals "true" or "false",
83+
are returned as booleans. All other non-None values are returned as
84+
strings. For attributes or properties which does not exist, None is returned.
7785
7886
:Args:
79-
- name - name of the attribute property to retieve.
87+
- name - Name of the attribute/property to retrieve.
8088
8189
Example::
8290
83-
# Check if the 'active' css class is applied to an element.
84-
is_active = "active" in target_element.get_attribute("class")
85-
86-
"""
91+
# Check if the "active" CSS class is applied to an element.
92+
is_active = "active" in target_element.get_attribute("class")"""
8793
resp = self._execute(Command.GET_ELEMENT_ATTRIBUTE, {'name': name})
8894
attributeValue = ''
8995
if resp['value'] is None:
@@ -92,7 +98,6 @@ def get_attribute(self, name):
9298
attributeValue = resp['value']
9399
if name != 'value' and attributeValue.lower() in ('true', 'false'):
94100
attributeValue = attributeValue.lower()
95-
96101
return attributeValue
97102

98103
def is_selected(self):

0 commit comments

Comments
 (0)