Skip to content

Commit e5909ed

Browse files
committed
fix: Handling of dictionary-values in WebElement.get_attribute()
fix: Catch NameError caused by missing unicode()-function and instead use str() when using Python 3
1 parent 9e1959c commit e5909ed

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

appium/webdriver/webelement.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ def get_attribute(self, name):
5959
if attributeValue is None:
6060
return None
6161

62+
if isinstance(attributeValue, dict):
63+
return attributeValue
64+
6265
if not isinstance(attributeValue, str):
63-
attributeValue = unicode(attributeValue)
66+
try:
67+
attributeValue = unicode(attributeValue)
68+
except NameError:
69+
attributeValue = str(attributeValue)
6470

6571
if name != 'value' and attributeValue.lower() in ('true', 'false'):
6672
return attributeValue.lower()

test/unit/webdriver/webelement_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,26 @@ def test_send_key_with_file(self):
7575

7676
d = get_httpretty_request_body(httpretty.last_request())
7777
assert d['text'] == ''.join(d['value'])
78+
79+
@httpretty.activate
80+
def test_get_attribute_with_dict(self):
81+
driver = android_w3c_driver()
82+
rect_dict = {
83+
'y': 200,
84+
'x': 100,
85+
'width': 300,
86+
'height': 56
87+
}
88+
httpretty.register_uri(
89+
httpretty.GET,
90+
appium_command('/session/1234567890/element/element_id/attribute/rect'),
91+
body=json.dumps({"value": rect_dict})
92+
)
93+
94+
element = MobileWebElement(driver, 'element_id', w3c=True)
95+
ef = element.get_attribute('rect')
96+
97+
d = httpretty.last_request()
98+
99+
assert isinstance(ef, dict)
100+
assert ef == rect_dict

0 commit comments

Comments
 (0)