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 131bd70

Browse files
authored
Merge pull request #3545 from seleniumbase/cdp-mode-patch-35
CDP Mode - Patch 35
2 parents c963804 + 978094d commit 131bd70

File tree

11 files changed

+62
-24
lines changed

11 files changed

+62
-24
lines changed

‎examples/cdp_mode/ReadMe.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ element.clear_input()
507507
element.click()
508508
element.flash(duration=0.5, color="EE4488")
509509
element.focus()
510+
element.gui_click(timeframe=0.25)
510511
element.highlight_overlay()
511512
element.mouse_click()
512513
element.mouse_drag(destination)

‎examples/cdp_mode/raw_cf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""Using CDP Mode with PyAutoGUI to bypass CAPTCHAs."""
22
from seleniumbase import SB
33

4-
with SB(uc=True, test=True, locale_code="en") as sb:
4+
with SB(uc=True, test=True, locale_code="en", incognito=True) as sb:
55
url = "https://www.cloudflare.com/login"
66
sb.activate_cdp_mode(url)
77
sb.sleep(3)
88
sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar
99
sb.sleep(2)
1010

11-
with SB(uc=True, test=True, locale_code="en") as sb:
11+
with SB(uc=True, test=True, locale_code="en", incognito=True) as sb:
1212
url = "https://www.cloudflare.com/login"
1313
sb.activate_cdp_mode(url)
1414
sb.sleep(2)

‎examples/cdp_mode/raw_elal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
print("*** Lowest Price: ***")
2727
lowest_price = sorted(prices)[0]
2828
print(lowest_price)
29+
sb.cdp.scroll_down(12)
30+
sb.sleep(1)
2931
sb.cdp.find_element_by_text(lowest_price).click()
3032
sb.sleep(1)
3133
search_cell = 'button[aria-label*="Search.cell.buttonTitle"]'

‎examples/test_usefixtures.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
@pytest.mark.usefixtures("sb")
55
class Test_UseFixtures:
66
def test_usefixtures_on_class(self):
7+
if not hasattr(self, "sb"):
8+
print("This test is for pytest only!")
9+
return
710
sb = self.sb
811
sb.open("https://seleniumbase.io/realworld/login")
912
sb.type("#username", "demo_user")

‎mkdocs_build/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pathspec==0.12.1
1414
Babel==2.17.0
1515
paginate==0.5.7
1616
mkdocs==1.6.1
17-
mkdocs-material==9.6.4
17+
mkdocs-material==9.6.5
1818
mkdocs-exclude-search==0.6.6
1919
mkdocs-simple-hooks==0.1.5
2020
mkdocs-material-extensions==1.3.1

‎requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ filelock~=3.16.1;python_version<"3.9"
1212
filelock>=3.17.0;python_version>="3.9"
1313
fasteners>=0.19
1414
mycdp>=1.1.0
15-
pynose>=1.5.3
15+
pynose>=1.5.4
1616
platformdirs>=4.3.6
1717
typing-extensions>=4.12.2
1818
sbvirtualdisplay>=1.4.0

‎seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.34.16"
2+
__version__ = "4.34.17"

‎seleniumbase/core/sb_cdp.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def __add_sync_methods(self, element):
5656
element, *args, **kwargs
5757
)
5858
element.focus = lambda: self.__focus(element)
59+
element.gui_click = (
60+
lambda *args, **kwargs: self.__gui_click(element, *args, **kwargs)
61+
)
5962
element.highlight_overlay = lambda: self.__highlight_overlay(element)
6063
element.mouse_click = lambda: self.__mouse_click(element)
6164
element.mouse_drag = (
@@ -426,6 +429,39 @@ def __focus(self, element):
426429
self.loop.run_until_complete(element.focus_async())
427430
)
428431

432+
def __gui_click(self, element, timeframe=None):
433+
element.scroll_into_view()
434+
self.__add_light_pause()
435+
position = element.get_position()
436+
x = position.x
437+
y = position.y
438+
e_width = position.width
439+
e_height = position.height
440+
# Relative to window
441+
element_rect = {"height": e_height, "width": e_width, "x": x, "y": y}
442+
window_rect = self.get_window_rect()
443+
w_bottom_y = window_rect["y"] + window_rect["height"]
444+
viewport_height = window_rect["innerHeight"]
445+
x = window_rect["x"] + element_rect["x"]
446+
y = w_bottom_y - viewport_height + element_rect["y"]
447+
y_scroll_offset = window_rect["pageYOffset"]
448+
y = y - y_scroll_offset
449+
x = x + window_rect["scrollX"]
450+
y = y + window_rect["scrollY"]
451+
# Relative to screen
452+
element_rect = {"height": e_height, "width": e_width, "x": x, "y": y}
453+
e_width = element_rect["width"]
454+
e_height = element_rect["height"]
455+
e_x = element_rect["x"]
456+
e_y = element_rect["y"]
457+
x, y = ((e_x + e_width / 2.0) + 0.5), ((e_y + e_height / 2.0) + 0.5)
458+
if not timeframe or not isinstance(timeframe, (int, float)):
459+
timeframe = 0.25
460+
if timeframe > 3:
461+
timeframe = 3
462+
self.gui_click_x_y(x, y, timeframe=timeframe)
463+
return self.loop.run_until_complete(self.page.wait())
464+
429465
def __highlight_overlay(self, element):
430466
return (
431467
self.loop.run_until_complete(element.highlight_overlay_async())
@@ -461,9 +497,7 @@ def __press_keys(self, element, text):
461497
element.send_keys("\r\n")
462498
time.sleep(0.044)
463499
self.__slow_mode_pause_if_set()
464-
return (
465-
self.loop.run_until_complete(self.page.wait())
466-
)
500+
return self.loop.run_until_complete(self.page.wait())
467501

468502
def __query_selector(self, element, selector):
469503
selector = self.__convert_to_css_if_xpath(selector)

‎seleniumbase/plugins/base_plugin.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ def configure(self, options, conf):
208208
self.duration = float(0)
209209
self.page_results_list = []
210210
self.test_count = 0
211-
self.import_error = False
212211
log_path = constants.Logs.LATEST + "/"
213212
archive_logs = options.archive_logs
214213
log_helper.log_folder_setup(log_path, archive_logs)
@@ -238,6 +237,7 @@ def beforeTest(self, test):
238237
)
239238
else:
240239
variables = {}
240+
test.test.test_id = test.id()
241241
test.test.is_nosetest = True
242242
test.test.environment = self.options.environment
243243
test.test.env = self.options.environment # Add a shortened version
@@ -263,17 +263,16 @@ def finalize(self, result):
263263
)
264264
log_helper.clear_empty_logs()
265265
if self.report_on:
266-
if not self.import_error:
267-
report_helper.add_bad_page_log_file(self.page_results_list)
268-
report_log_path = report_helper.archive_new_report_logs()
269-
report_helper.build_report(
270-
report_log_path,
271-
self.page_results_list,
272-
self.successes,
273-
self.failures,
274-
self.options.browser,
275-
self.show_report,
276-
)
266+
report_helper.add_bad_page_log_file(self.page_results_list)
267+
report_log_path = report_helper.archive_new_report_logs()
268+
report_helper.build_report(
269+
report_log_path,
270+
self.page_results_list,
271+
self.successes,
272+
self.failures,
273+
self.options.browser,
274+
self.show_report,
275+
)
277276

278277
def addSuccess(self, test, capt):
279278
if self.report_on:
@@ -293,9 +292,6 @@ def add_fails_or_errors(self, test, err):
293292
"%.2fs" % (float(time.time()) - float(self.start_time))
294293
)
295294
if test.id() == "nose.failure.Failure.runTest":
296-
print(">>> ERROR: Could not locate tests to run!")
297-
print(">>> The Test Report WILL NOT be generated!")
298-
self.import_error = True
299295
return
300296
self.failures.append(test.id())
301297
self.page_results_list.append(
@@ -314,6 +310,7 @@ def add_fails_or_errors(self, test, err):
314310
test._log_fail_data()
315311
sb_config._excinfo_tb = err
316312
log_path = None
313+
source = None
317314
if hasattr(sb_config, "_test_logpath"):
318315
log_path = sb_config._test_logpath
319316
if hasattr(sb_config, "_last_page_source"):

‎seleniumbase/plugins/selenium_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ def beforeTest(self, test):
13091309
test.test.dashboard = False
13101310
test.test._multithreaded = False
13111311
test.test._reuse_session = False
1312+
sb_config.recorder_mode = test.test.recorder_mode
13121313
sb_config.no_screenshot = test.test.no_screenshot_after_test
13131314
if test.test.servername != "localhost":
13141315
# Using Selenium Grid

0 commit comments

Comments
(0)

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