Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support list attribute #934

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions appium/webdriver/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WebElement(SeleniumWebElement):
_execute: Callable
_id: str

def get_attribute(self, name: str) -> Optional[Union[str, Dict]]:
def get_attribute(self, name: str) -> Optional[Union[str, Dict, List]]:
"""Gets the given attribute or property of the element.

Override for Appium
Expand Down Expand Up @@ -60,7 +60,7 @@ def get_attribute(self, name: str) -> Optional[Union[str, Dict]]:
if attribute_value is None:
return None

if isinstance(attribute_value, dict):
if isinstance(attribute_value, dict) or isinstance(attribute_value, list):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the return type must be updated as well and then (probably) mypy output fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also isinstance may accept a tuple as the second argument

return attribute_value

# Convert to str along to the spec
Expand Down
18 changes: 16 additions & 2 deletions test/unit/webdriver/webelement_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@ def test_get_attribute_with_dict(self):
element = MobileWebElement(driver, 'element_id')
ef = element.get_attribute('rect')

d = httpretty.last_request()

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

@httpretty.activate
def test_get_attribute_with_list(self):
driver = android_w3c_driver()
mixed_list = ['abc', 123, True]
httpretty.register_uri(
httpretty.GET,
appium_command('/session/1234567890/element/element_id/attribute/mixed'),
body=json.dumps({"value": mixed_list}),
)

element = MobileWebElement(driver, 'element_id')
l = element.get_attribute('mixed')

assert isinstance(l, list)
assert l == mixed_list