Gets the given attribute or property of the element. This method will first try to return the value of a property with the given name. If a property with that name doesn't exist, it returns the value of the attribute with the same name. If there's no attribute with t
(self, name)
| 182 | return self._execute(Command.GET_ELEMENT_ATTRIBUTE, {"name": name})["value"] |
| 183 | |
| 184 | def get_attribute(self, name) -> str | None: |
| 185 | """Gets the given attribute or property of the element. |
| 186 | |
| 187 | This method will first try to return the value of a property with the |
| 188 | given name. If a property with that name doesn't exist, it returns the |
| 189 | value of the attribute with the same name. If there's no attribute with |
| 190 | that name, ``None`` is returned. |
| 191 | |
| 192 | Values which are considered truthy, that is equals "true" or "false", |
| 193 | are returned as booleans. All other non-``None`` values are returned |
| 194 | as strings. For attributes or properties which do not exist, ``None`` |
| 195 | is returned. |
| 196 | |
| 197 | To obtain the exact value of the attribute or property, |
| 198 | use :func:`~selenium.webdriver.remote.BaseWebElement.get_dom_attribute` or |
| 199 | :func:`~selenium.webdriver.remote.BaseWebElement.get_property` methods respectively. |
| 200 | |
| 201 | Args: |
| 202 | name: Name of the attribute/property to retrieve. |
| 203 | |
| 204 | Returns: |
| 205 | The value of the attribute/property. |
| 206 | |
| 207 | Example: |
| 208 | # Check if the "active" CSS class is applied to an element. |
| 209 | is_active = "active" in target_element.get_attribute("class") |
| 210 | """ |
| 211 | if getAttribute_js is None: |
| 212 | _load_js() |
| 213 | attribute_value = self.parent.execute_script( |
| 214 | f"/* getAttribute */return ({getAttribute_js}).apply(null, arguments);", self, name |
| 215 | ) |
| 216 | return attribute_value |
| 217 | |
| 218 | def is_selected(self) -> bool: |
| 219 | """Returns whether the element is selected. |