Skip to content

Support applications with multiple webviews. Add scrolling to the visible webview. #329

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

Merged
merged 7 commits into from
Dec 23, 2021
Merged
22 changes: 22 additions & 0 deletions AppiumLibrary/keywords/_applicationmanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ def switch_to_parent_frame(self):
"""
self._current_application().switch_to.parent_frame()

def switch_to_window(self, window_name):
"""
Switch to a new webview window if the application contains multiple webviews
"""
self._current_application().switch_to.window(window_name)


def go_to_url(self, url):
"""
Opens URL in default web browser.
Expand All @@ -380,6 +387,21 @@ def get_capability(self, capability_name):
raise e
return capability

def get_window_title(self):
"""Get the current Webview window title."""
return self._current_application().title

def get_window_url(self):
"""Get the current Webview window URL."""
return self._current_application().current_url


def get_windows(self):
"""Get available Webview windows."""
print(self._current_application().window_handles)
return self._current_application().window_handles


# Private

def _current_application(self):
Expand Down
39 changes: 39 additions & 0 deletions AppiumLibrary/keywords/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,45 @@ def get_webelement(self, locator):
"""
return self._element_find(locator, True, True)

def scroll_element_into_view(self, locator):
"""Scrolls an element from given ``locator`` into view.
Arguments:
- ``locator``: The locator to find requested element. Key attributes for
arbitrary elements are ``id`` and ``name``. See `introduction` for
details about locating elements.
Examples:
| Scroll Element Into View | css=div.class |
"""
if isinstance(locator, WebElement):
element = locator
else:
self._info("Scrolling element '%s' into view." % locator)
element = self._element_find(locator, True, True)
script = 'arguments[0].scrollIntoView()'
# pylint: disable=no-member
self._current_application().execute_script(script, element)
Copy link
Owner

Choose a reason for hiding this comment

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

does this apply to both ios and android

Copy link
Contributor Author

@matthew-dahm matthew-dahm Oct 12, 2021

Choose a reason for hiding this comment

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

Confirmed to work for scrolling elements in a webview on both Android and iOS.

return element

def get_webelement_in_webelement(self, element, locator):
"""
Returns a single [http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.remote.webelement|WebElement]
objects matching ``locator`` that is a child of argument element.

This is useful when your HTML doesn't properly have id or name elements on all elements.
So the user can find an element with a tag and then search that elmements children.
"""
elements = None
if isstr(locator):
_locator = locator
elements = self._element_finder.find(element, _locator, None)
if len(elements) == 0:
raise ValueError("Element locator '" + locator + "' did not match any elements.")
if len(elements) == 0:
return None
return elements[0]
elif isinstance(locator, WebElement):
return locator

def get_webelements(self, locator):
"""Returns list of [http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.remote.webelement|WebElement] objects matching ``locator``.

Expand Down