Skip to content

Commit 9771cda

Browse files
committed
Update CDP Mode
1 parent 9289014 commit 9771cda

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

seleniumbase/core/browser_launcher.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,9 +1501,12 @@ def _uc_gui_click_captcha(
15011501
):
15021502
frame = '[data-callback="onCaptchaSuccess"]'
15031503
elif driver.is_element_present(
1504-
"div:not([class]) > div:not([class])"
1504+
"div:not([class]):not([id]) > div:not([class]):not([id])"
15051505
):
1506-
frame = "div:not([class]) > div:not([class])"
1506+
frame = (
1507+
"div:not([class]):not([id]) > "
1508+
"div:not([class]):not([id])"
1509+
)
15071510
else:
15081511
return False
15091512
if (

seleniumbase/core/sb_cdp.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,16 @@ def _on_an_incapsula_hcaptcha_page(self, *args, **kwargs):
19811981
return True
19821982
return False
19831983

1984+
def _on_a_datadome_slider_page(self, *args, **kwargs):
1985+
self.loop.run_until_complete(self.page.wait())
1986+
if (
1987+
self.is_element_visible(
1988+
'body > iframe[src*="/geo.captcha-delivery.com/captcha/"]'
1989+
)
1990+
):
1991+
return True
1992+
return False
1993+
19841994
def _on_a_g_recaptcha_page(self, *args, **kwargs):
19851995
time.sleep(0.4) # reCAPTCHA may need a moment to appear
19861996
self.loop.run_until_complete(self.page.wait())
@@ -2054,6 +2064,26 @@ def __gui_click_recaptcha(self, use_cdp=False):
20542064
return True
20552065
return False
20562066

2067+
def __gui_slide_datadome_captcha(self):
2068+
iframe = 'body > iframe[src*="/geo.captcha-delivery.com/captcha/"]'
2069+
if not self.is_element_visible(iframe):
2070+
return False
2071+
src = self.get_attribute(iframe, "src")
2072+
tab = self.get_active_tab()
2073+
self.open_new_tab(url=src)
2074+
time.sleep(0.41)
2075+
self.loop.run_until_complete(self.page.wait())
2076+
time.sleep(0.25)
2077+
x1, y1 = self.get_gui_element_center("div.slider")
2078+
x2, y2 = self.get_gui_element_center("div.sliderTarget")
2079+
self.close_active_tab()
2080+
self.switch_to_tab(tab)
2081+
self.gui_drag_drop_points(x1, y1, x2, y2, timeframe=0.55)
2082+
time.sleep(0.25)
2083+
self.loop.run_until_complete(self.page.wait())
2084+
time.sleep(0.15)
2085+
return True
2086+
20572087
def __cdp_click_incapsula_hcaptcha(self):
20582088
selector = "iframe[data-hcaptcha-widget-id]"
20592089
if self.is_element_visible('iframe[src*="_Incapsula_Resource?"]'):
@@ -2128,6 +2158,9 @@ def __click_captcha(self, use_cdp=False):
21282158
elif self._on_an_incapsula_hcaptcha_page():
21292159
result = self.__cdp_click_incapsula_hcaptcha()
21302160
return result
2161+
elif self._on_a_datadome_slider_page():
2162+
result = self.__gui_slide_datadome_captcha()
2163+
return result
21312164
else:
21322165
return False
21332166
selector = None
@@ -2174,9 +2207,11 @@ def __click_captcha(self, use_cdp=False):
21742207
):
21752208
selector = '[data-callback="onCaptchaSuccess"]'
21762209
elif self.is_element_present(
2177-
"div:not([class]) > div:not([class])"
2210+
"div:not([class]):not([id]) > div:not([class]):not([id])"
21782211
):
2179-
selector = "div:not([class]) > div:not([class])"
2212+
selector = (
2213+
"div:not([class]):not([id]) > div:not([class]):not([id])"
2214+
)
21802215
else:
21812216
return False
21822217
if not selector:

seleniumbase/undetected/cdp_driver/tab.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,9 +1669,11 @@ async def solve_captcha(self):
16691669
):
16701670
selector = '[data-callback="onCaptchaSuccess"]'
16711671
elif await self.is_element_present(
1672-
"div:not([class]) > div:not([class])"
1672+
"div:not([class]):not([id]) > div:not([class]):not([id])"
16731673
):
1674-
selector = "div:not([class]) > div:not([class])"
1674+
selector = (
1675+
"div:not([class]):not([id]) > div:not([class]):not([id])"
1676+
)
16751677
else:
16761678
return False
16771679
if not selector:

0 commit comments

Comments
 (0)