Skip to content

Commit dfb127d

Browse files
feat: add option to wait for promise in Element.apply method (#135)
* feat: add option to wait for promise in Element.apply method * Update element.py Co-authored-by: Stephan Lensky <[email protected]> * reorder doc --------- Co-authored-by: Stephan Lensky <[email protected]>
1 parent b5d6245 commit dfb127d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Added
1313

1414
- Added `speed` in `Tab.scroll_down` and `Tab.scroll_up` methods to control the scroll speed @nathanfallet
15+
- Allow to wait for promise in `Element.apply` method @nathanfallet
1516

1617
### Changed
1718

zendriver/core/element.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def __call__(self, js_method):
444444
"""
445445
return self.apply(f"(e) => e['{js_method}']()")
446446

447-
async def apply(self, js_function, return_by_value=True):
447+
async def apply(self, js_function, return_by_value=True, *, await_promise=False):
448448
"""
449449
apply javascript to this element. the given js_function string should accept the js element as parameter,
450450
and can be a arrow function, or function declaration.
@@ -457,6 +457,8 @@ async def apply(self, js_function, return_by_value=True):
457457
:type js_function: str
458458
:param return_by_value:
459459
:type return_by_value:
460+
:param await_promise: when True, waits for the promise to resolve before returning
461+
:type await_promise: bool
460462
:return:
461463
:rtype:
462464
"""
@@ -474,6 +476,7 @@ async def apply(self, js_function, return_by_value=True):
474476
],
475477
return_by_value=True,
476478
user_gesture=True,
479+
await_promise=await_promise,
477480
)
478481
)
479482
if result and result[0]:

0 commit comments

Comments
 (0)