|
20 | 20 |
|
21 | 21 | from .mobilecommand import MobileCommand as Command |
22 | 22 |
|
| 23 | +# Python 3 imports |
| 24 | +try: |
| 25 | + str = basestring |
| 26 | +except NameError: |
| 27 | + pass |
| 28 | + |
23 | 29 |
|
24 | 30 | class WebElement(SeleniumWebElement): |
| 31 | + # Override |
| 32 | + def get_attribute(self, name): |
| 33 | + """Gets the given attribute or property of the element. |
| 34 | +
|
| 35 | + This method will first try to return the value of a property with the |
| 36 | + given name. If a property with that name doesn't exist, it returns the |
| 37 | + value of the attribute with the same name. If there's no attribute with |
| 38 | + that name, ``None`` is returned. |
| 39 | +
|
| 40 | + Values which are considered truthy, that is equals "true" or "false", |
| 41 | + are returned as booleans. All other non-``None`` values are returned |
| 42 | + as strings. For attributes or properties which do not exist, ``None`` |
| 43 | + is returned. |
| 44 | +
|
| 45 | + :Args: |
| 46 | + - name - Name of the attribute/property to retrieve. |
| 47 | +
|
| 48 | + Example:: |
| 49 | +
|
| 50 | + # Check if the "active" CSS class is applied to an element. |
| 51 | + is_active = "active" in target_element.get_attribute("class") |
| 52 | +
|
| 53 | + """ |
| 54 | + |
| 55 | + resp = self._execute(RemoteCommand.GET_ELEMENT_ATTRIBUTE, {'name': name}) |
| 56 | + attributeValue = resp.get('value') |
| 57 | + |
| 58 | + if attributeValue is None: |
| 59 | + return None |
| 60 | + |
| 61 | + if not isinstance(attributeValue, str): |
| 62 | + attributeValue = unicode(attributeValue) |
| 63 | + |
| 64 | + if name != 'value' and attributeValue.lower() in ('true', 'false'): |
| 65 | + return attributeValue.lower() |
| 66 | + |
| 67 | + return attributeValue |
| 68 | + |
| 69 | + # Override |
| 70 | + def is_displayed(self): |
| 71 | + """Whether the element is visible to a user.""" |
| 72 | + return self._execute(RemoteCommand.IS_ELEMENT_DISPLAYED)['value'] |
| 73 | + |
25 | 74 | def find_element_by_ios_uiautomation(self, uia_string): |
26 | 75 | """Finds an element by uiautomation in iOS. |
27 | 76 |
|
|
0 commit comments