Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c2d4f54

Browse files
committed
Add method to clear input fields in CDP Mode
1 parent f102ced commit c2d4f54

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

‎examples/cdp_mode/ReadMe.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ sb.cdp.send_keys(selector, text, timeout=None)
411411
sb.cdp.press_keys(selector, text, timeout=None)
412412
sb.cdp.type(selector, text, timeout=None)
413413
sb.cdp.set_value(selector, text, timeout=None)
414+
sb.cdp.clear_input(selector, timeout=None)
415+
sb.cdp.clear(selector, timeout=None)
414416
sb.cdp.submit(selector)
415417
sb.cdp.evaluate(expression)
416418
sb.cdp.js_dumps(obj_name)

‎seleniumbase/core/browser_launcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ def uc_open_with_cdp_mode(driver, url=None, **kwargs):
742742
cdp.send_keys = CDPM.send_keys
743743
cdp.press_keys = CDPM.press_keys
744744
cdp.type = CDPM.type
745+
cdp.clear_input = CDPM.clear_input
746+
cdp.clear = CDPM.clear_input
745747
cdp.set_value = CDPM.set_value
746748
cdp.submit = CDPM.submit
747749
cdp.evaluate = CDPM.evaluate

‎seleniumbase/core/sb_cdp.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,16 @@ def type(self, selector, text, timeout=None):
937937
self.__slow_mode_pause_if_set()
938938
self.loop.run_until_complete(self.page.sleep(0.025))
939939

940+
def clear_input(self, selector, timeout=None):
941+
if not timeout:
942+
timeout = settings.SMALL_TIMEOUT
943+
self.__slow_mode_pause_if_set()
944+
element = self.select(selector, timeout=timeout)
945+
element.scroll_into_view()
946+
element.clear_input()
947+
self.__slow_mode_pause_if_set()
948+
self.loop.run_until_complete(self.page.sleep(0.025))
949+
940950
def set_value(self, selector, text, timeout=None):
941951
"""Similar to send_keys(), but clears the text field first."""
942952
if not timeout:

‎seleniumbase/fixtures/base_case.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,9 @@ def clear(self, selector, by="css selector", timeout=None):
11941194
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
11951195
timeout = self.__get_new_timeout(timeout)
11961196
selector, by = self.__recalculate_selector(selector, by)
1197+
if self.__is_cdp_swap_needed():
1198+
self.cdp.clear_input(selector)
1199+
return
11971200
if self.__is_shadow_selector(selector):
11981201
self.__shadow_clear(selector, timeout)
11991202
return

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /