Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion appium/webdriver/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ def get_attribute(self, name):
if attributeValue is None:
return None

if isinstance(attributeValue, dict):
return attributeValue

if not isinstance(attributeValue, str):
attributeValue = unicode(attributeValue)
try:
attributeValue = unicode(attributeValue)
except NameError:
attributeValue = str(attributeValue)

if name != 'value' and attributeValue.lower() in ('true', 'false'):
return attributeValue.lower()
Expand Down
23 changes: 23 additions & 0 deletions test/unit/webdriver/webelement_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,26 @@ def test_send_key_with_file(self):

d = get_httpretty_request_body(httpretty.last_request())
assert d['text'] == ''.join(d['value'])

@httpretty.activate
def test_get_attribute_with_dict(self):
driver = android_w3c_driver()
rect_dict = {
'y': 200,
'x': 100,
'width': 300,
'height': 56
}
httpretty.register_uri(
httpretty.GET,
appium_command('/session/1234567890/element/element_id/attribute/rect'),
body=json.dumps({"value": rect_dict})
)

element = MobileWebElement(driver, 'element_id', w3c=True)
ef = element.get_attribute('rect')

d = httpretty.last_request()

assert isinstance(ef, dict)
assert ef == rect_dict