Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ sb.cdp.gui_press_keys(keys)
sb.cdp.gui_write(text)
sb.cdp.gui_click_x_y(x, y, timeframe=0.25)
sb.cdp.gui_click_element(selector, timeframe=0.25)
sb.cdp.gui_click_captcha()
sb.cdp.gui_drag_drop_points(x1, y1, x2, y2, timeframe=0.35)
sb.cdp.gui_drag_and_drop(drag_selector, drop_selector, timeframe=0.35)
sb.cdp.gui_click_and_hold(selector, timeframe=0.35)
Expand Down
8 changes: 8 additions & 0 deletions examples/cdp_mode/raw_cdp_turnstile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from seleniumbase import sb_cdp

url = "https://seleniumbase.io/apps/turnstile"
sb = sb_cdp.Chrome(url)
sb.gui_click_captcha()
sb.assert_element("img#captcha-success")
sb.sleep(2)
sb.driver.stop()
18 changes: 18 additions & 0 deletions examples/cdp_mode/raw_cf_clearance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from seleniumbase import sb_cdp

url = "https://gitlab.com/users/sign_in"
sb = sb_cdp.Chrome(url)
sb.sleep(2.2)
sb.gui_click_captcha()
sb.sleep(2)
cf_cookie = None
all_cookies = sb.get_all_cookies()
for cookie in all_cookies:
if cookie.name == 'cf_clearance':
cf_cookie = cookie
break
if cf_cookie:
print("cf_clearance cookie: %s" % cf_cookie.value)
else:
print("Didn't find the cf_clearance cookie!")
sb.driver.stop()
4 changes: 2 additions & 2 deletions examples/cdp_mode/raw_consecutive_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
with SB(uc=True, test=True) as sb:
url = "https://sms-man.com/login"
sb.activate_cdp_mode(url)
sb.sleep(2)
sb.sleep(2.2)
sb.uc_gui_click_captcha()
sb.sleep(2)
sb.sleep(2.2)
sb.uc_gui_click_captcha()
sb.sleep(2)
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with SB(uc=True, test=True, locale="en") as sb:
url = "https://gitlab.com/users/sign_in"
sb.activate_cdp_mode(url)
sb.sleep(1)
sb.sleep(2.2)
sb.uc_gui_click_captcha()
sb.assert_text("Username", '[for="user_login"]', timeout=3)
sb.assert_element('label[for="user_login"]')
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_glassdoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with SB(uc=True, test=True, ad_block=True) as sb:
url = "https://www.glassdoor.com/Reviews/index.htm"
sb.activate_cdp_mode(url)
sb.sleep(2)
sb.sleep(2.2)
sb.uc_gui_click_captcha()
sb.highlight('[data-test="global-nav-glassdoor-logo"]')
sb.highlight('[data-test="site-header-companies"]')
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_indeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with SB(uc=True, test=True) as sb:
url = "https://www.indeed.com/companies/search"
sb.activate_cdp_mode(url)
sb.sleep(2)
sb.sleep(2.2)
sb.uc_gui_click_captcha()
sb.sleep(1)
company = "NASA Jet Propulsion Laboratory"
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pathspec==0.12.1
Babel==2.17.0
paginate==0.5.7
mkdocs==1.6.1
mkdocs-material==9.6.17
mkdocs-material==9.6.18
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fasteners>=0.20
mycdp>=1.2.0
pynose>=1.5.4
platformdirs>=4.3.6;python_version<"3.9"
platformdirs>=4.3.8;python_version>="3.9"
platformdirs>=4.4.0;python_version>="3.9"
typing-extensions>=4.13.2
sbvirtualdisplay>=1.4.0
MarkupSafe==2.1.5;python_version<"3.9"
Expand All @@ -35,7 +35,8 @@ chardet==5.2.0
charset-normalizer>=3.4.3,<4
urllib3>=1.26.20,<2;python_version<"3.10"
urllib3>=1.26.20,<2.6.0;python_version>="3.10"
requests==2.32.4
requests==2.32.4;python_version<"3.9"
requests>=2.32.5,<2.33;python_version>="3.9"
sniffio==1.3.1
h11==0.16.0
outcome==1.3.0.post0
Expand Down Expand Up @@ -66,7 +67,7 @@ pytest-xdist==3.8.0;python_version>="3.9"
parameterized==0.9.0
behave==1.2.6
soupsieve==2.7
beautifulsoup4==4.13.4
beautifulsoup4>=4.13.5,<4.14
pyotp==2.9.0
python-xlib==0.33;platform_system=="Linux"
markdown-it-py==3.0.0;python_version<"3.10"
Expand All @@ -78,7 +79,7 @@ rich>=14.1.0,<15
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)

coverage>=7.6.1;python_version<"3.9"
coverage>=7.10.4;python_version>="3.9"
coverage>=7.10.5;python_version>="3.9"
pytest-cov>=5.0.0;python_version<"3.9"
pytest-cov>=6.2.1;python_version>="3.9"
flake8==5.0.4;python_version<"3.9"
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.41.1"
__version__ = "4.41.2"
1 change: 1 addition & 0 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ def uc_open_with_cdp_mode(driver, url=None, **kwargs):
cdp.gui_write = CDPM.gui_write
cdp.gui_click_x_y = CDPM.gui_click_x_y
cdp.gui_click_element = CDPM.gui_click_element
cdp.gui_click_captcha = CDPM.gui_click_captcha
cdp.gui_drag_drop_points = CDPM.gui_drag_drop_points
cdp.gui_drag_and_drop = CDPM.gui_drag_and_drop
cdp.gui_click_and_hold = CDPM.gui_click_and_hold
Expand Down
146 changes: 146 additions & 0 deletions seleniumbase/core/sb_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,152 @@ def gui_click_element(self, selector, timeframe=0.25):
self.__slow_mode_pause_if_set()
self.loop.run_until_complete(self.page.wait())

def _on_a_cf_turnstile_page(self):
source = self.get_page_source()
if (
'data-callback="onCaptchaSuccess"' in source
or "/challenge-platform/scripts/" in source
or 'id="challenge-widget-' in source
or "cf-turnstile-" in source
):
return True
return False

def gui_click_captcha(self):
if not self._on_a_cf_turnstile_page():
return
selector = None
if (
self.is_element_present('[name*="cf-turnstile-"]')
and self.is_element_present("#challenge-form div > div")
):
selector = "#challenge-form div > div"
elif (
self.is_element_present('[name*="cf-turnstile-"]')
and self.is_element_present(
'[style="display: grid;"] div div'
)
):
selector = '[style="display: grid;"] div div'
elif (
self.is_element_present('[name*="cf-turnstile-"]')
and self.is_element_present("[class*=spacer] + div div")
):
selector = '[class*=spacer] + div div'
elif (
self.is_element_present('[name*="cf-turnstile-"]')
and self.is_element_present("div.spacer div")
):
selector = "div.spacer div"
elif (
self.is_element_present('script[src*="challenges.c"]')
and self.is_element_present(
'[data-testid*="challenge-"] div'
)
):
selector = '[data-testid*="challenge-"] div'
elif self.is_element_present(
"div#turnstile-widget div:not([class])"
):
selector = "div#turnstile-widget div:not([class])"
elif self.is_element_present(
'form div:not([class]):has(input[name*="cf-turn"])'
):
selector = 'form div:not([class]):has(input[name*="cf-turn"])'
elif (
self.is_element_present('[src*="/turnstile/"]')
and self.is_element_present("form div:not(:has(*))")
):
selector = "form div:not(:has(*))"
elif (
self.is_element_present('[src*="/turnstile/"]')
and self.is_element_present(
"body > div#check > div:not([class])"
)
):
selector = "body > div#check > div:not([class])"
elif self.is_element_present(".cf-turnstile-wrapper"):
selector = ".cf-turnstile-wrapper"
elif self.is_element_present('[class="cf-turnstile"]'):
selector = '[class="cf-turnstile"]'
elif self.is_element_present(
'[data-callback="onCaptchaSuccess"]'
):
selector = '[data-callback="onCaptchaSuccess"]'
else:
return
if not selector:
return
if (
self.is_element_present("form")
and (
self.is_element_present('form[class*="center"]')
or self.is_element_present('form[class*="right"]')
or self.is_element_present('form div[class*="center"]')
or self.is_element_present('form div[class*="right"]')
)
):
script = (
"""var $elements = document.querySelectorAll(
'form[class], form div[class]');
var index = 0, length = $elements.length;
for(; index < length; index++){
the_class = $elements[index].getAttribute('class');
new_class = the_class.replaceAll('center', 'left');
new_class = new_class.replaceAll('right', 'left');
$elements[index].setAttribute('class', new_class);}"""
)
with suppress(Exception):
self.loop.run_until_complete(self.page.evaluate(script))
self.loop.run_until_complete(self.page.wait())
elif (
self.is_element_present("form")
and (
self.is_element_present('form div[style*="center"]')
or self.is_element_present('form div[style*="right"]')
)
):
script = (
"""var $elements = document.querySelectorAll(
'form[style], form div[style]');
var index = 0, length = $elements.length;
for(; index < length; index++){
the_style = $elements[index].getAttribute('style');
new_style = the_style.replaceAll('center', 'left');
new_style = new_style.replaceAll('right', 'left');
$elements[index].setAttribute('style', new_style);}"""
)
with suppress(Exception):
self.loop.run_until_complete(self.page.evaluate(script))
self.loop.run_until_complete(self.page.wait())
elif (
self.is_element_present("form")
and self.is_element_present(
'form [id*="turnstile"] > div:not([class])'
)
):
script = (
"""var $elements = document.querySelectorAll(
'form [id*="turnstile"]');
var index = 0, length = $elements.length;
for(; index < length; index++){
$elements[index].setAttribute('align', 'left');}"""
)
with suppress(Exception):
self.loop.run_until_complete(self.page.evaluate(script))
self.loop.run_until_complete(self.page.wait())
with suppress(Exception):
element_rect = self.get_gui_element_rect(selector, timeout=1)
e_x = element_rect["x"]
e_y = element_rect["y"]
x = e_x + 32
if not shared_utils.is_windows():
y = e_y + 32
else:
y = e_y + 22
sb_config._saved_cf_x_y = (x, y)
self.gui_click_x_y(x, y)

def __gui_drag_drop(self, x1, y1, x2, y2, timeframe=0.25, uc_lock=False):
self.__install_pyautogui_if_missing()
import pyautogui
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"mycdp>=1.2.0",
"pynose>=1.5.4",
'platformdirs>=4.3.6;python_version<"3.9"',
'platformdirs>=4.3.8;python_version>="3.9"',
'platformdirs>=4.4.0;python_version>="3.9"',
'typing-extensions>=4.13.2',
"sbvirtualdisplay>=1.4.0",
'MarkupSafe==2.1.5;python_version<"3.9"',
Expand All @@ -183,7 +183,8 @@
'charset-normalizer>=3.4.3,<4',
'urllib3>=1.26.20,<2;python_version<"3.10"',
'urllib3>=1.26.20,<2.6.0;python_version>="3.10"',
'requests==2.32.4',
'requests==2.32.4;python_version<"3.9"',
'requests>=2.32.5,<2.33;python_version>="3.9"',
'sniffio==1.3.1',
'h11==0.16.0',
'outcome==1.3.0.post0',
Expand Down Expand Up @@ -214,7 +215,7 @@
'parameterized==0.9.0',
"behave==1.2.6", # Newer ones had issues
'soupsieve==2.7',
"beautifulsoup4==4.13.4",
"beautifulsoup4>=4.13.5,<4.14",
'pyotp==2.9.0',
'python-xlib==0.33;platform_system=="Linux"',
'markdown-it-py==3.0.0;python_version<"3.10"',
Expand All @@ -235,7 +236,7 @@
# Usage: coverage run -m pytest; coverage html; coverage report
"coverage": [
'coverage>=7.6.1;python_version<"3.9"',
'coverage>=7.10.4;python_version>="3.9"',
'coverage>=7.10.5;python_version>="3.9"',
'pytest-cov>=5.0.0;python_version<"3.9"',
'pytest-cov>=6.2.1;python_version>="3.9"',
],
Expand Down