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: add "order" to choose specific element, support dynamic change sleep time #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions wda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,12 +1485,14 @@ def find_elements(self):
def count(self):
return len(self.find_element_ids())

def get(self, timeout=None, raise_error=True):
def get(self, timeout=None, raise_error=True, order=1, retry=1):
"""
Args:
timeout (float): timeout for query element, unit seconds
Default 10s
raise_error (bool): whether to raise error if element not found
order (int): if find more than one element, choose the specific by use order. range: [1,n]
retry (int): dynamic change sleep time

Returns:
Element: UI Element
Expand All @@ -1501,13 +1503,17 @@ def get(self, timeout=None, raise_error=True):
start_time = time.time()
if timeout is None:
timeout = self._timeout
internal = timeout / retry
while True:
elems = self.find_elements()
if len(elems) > 0:
return elems[0]
if order - 1 < len(elems):
return elems[order - 1]
else:
return elems[0]
if start_time + timeout < time.time():
break
time.sleep(0.5)
time.sleep(internal)

if raise_error:
raise WDAElementNotFoundError("element not found",
Expand Down