Skip to content

Commit ab52f99

Browse files
authored
Merge pull request #3593 from seleniumbase/cdp-mode-patch-41
CDP Mode: Patch 41
2 parents 24f4a91 + 7c73ae3 commit ab52f99

File tree

7 files changed

+87
-7
lines changed

7 files changed

+87
-7
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# An example of bypassing 2 consecutive CF CAPTCHAs"""
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True) as sb:
5+
url = "https://sms-man.com/login"
6+
sb.activate_cdp_mode(url)
7+
sb.sleep(2)
8+
sb.uc_gui_click_captcha()
9+
sb.sleep(2)
10+
sb.uc_gui_click_captcha()
11+
sb.sleep(2)

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ attrs>=25.1.0
77
certifi>=2025.1.31
88
exceptiongroup>=1.2.2
99
websockets~=13.1;python_version<"3.9"
10-
websockets>=15.0;python_version>="3.9"
10+
websockets>=15.0.1;python_version>="3.9"
1111
filelock~=3.16.1;python_version<"3.9"
1212
filelock>=3.17.0;python_version>="3.9"
1313
fasteners>=0.19
@@ -18,7 +18,7 @@ typing-extensions>=4.12.2
1818
sbvirtualdisplay>=1.4.0
1919
MarkupSafe==2.1.5;python_version<"3.9"
2020
MarkupSafe>=3.0.2;python_version>="3.9"
21-
Jinja2>=3.1.5
21+
Jinja2>=3.1.6
2222
six>=1.17.0
2323
parse>=1.20.2
2424
parse-type>=0.6.4

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.35.4"
2+
__version__ = "4.35.5"

seleniumbase/core/browser_launcher.py

+37-2
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,13 @@ def _uc_gui_click_captcha(
12881288
and driver.is_element_present("form div:not(:has(*))")
12891289
):
12901290
frame = "form div:not(:has(*))"
1291+
elif (
1292+
driver.is_element_present('[src*="/turnstile/"]')
1293+
and driver.is_element_present(
1294+
"body > div#check > div:not([class])"
1295+
)
1296+
):
1297+
frame = "body > div#check > div:not([class])"
12911298
elif driver.is_element_present(".cf-turnstile-wrapper"):
12921299
frame = ".cf-turnstile-wrapper"
12931300
elif driver.is_element_present(
@@ -1319,15 +1326,36 @@ def _uc_gui_click_captcha(
13191326
driver.cdp.evaluate(script)
13201327
else:
13211328
driver.execute_script(script)
1329+
elif (
1330+
driver.is_element_present("form")
1331+
and (
1332+
driver.is_element_present('form div[style*="center"]')
1333+
or driver.is_element_present('form div[style*="right"]')
1334+
)
1335+
):
1336+
script = (
1337+
"""var $elements = document.querySelectorAll(
1338+
'form[style], form div[style]');
1339+
var index = 0, length = $elements.length;
1340+
for(; index < length; index++){
1341+
the_style = $elements[index].getAttribute('style');
1342+
new_style = the_style.replaceAll('center', 'left');
1343+
new_style = new_style.replaceAll('right', 'left');
1344+
$elements[index].setAttribute('style', new_style);}"""
1345+
)
1346+
if __is_cdp_swap_needed(driver):
1347+
driver.cdp.evaluate(script)
1348+
else:
1349+
driver.execute_script(script)
13221350
elif (
13231351
driver.is_element_present("form")
13241352
and driver.is_element_present(
1325-
"form.turnstile #turnstile-widget > div:not([class])"
1353+
'form [id*="turnstile"] > div:not([class])'
13261354
)
13271355
):
13281356
script = (
13291357
"""var $elements = document.querySelectorAll(
1330-
'form.turnstile #turnstile-widget');
1358+
'form [id*="turnstile"]');
13311359
var index = 0, length = $elements.length;
13321360
for(; index < length; index++){
13331361
$elements[index].setAttribute('align', 'left');}"""
@@ -1577,6 +1605,13 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
15771605
):
15781606
frame = "form div:not(:has(*))"
15791607
tab_up_first = True
1608+
elif (
1609+
driver.is_element_present('[src*="/turnstile/"]')
1610+
and driver.is_element_present(
1611+
"body > div#check > div:not([class])"
1612+
)
1613+
):
1614+
frame = "body > div#check > div:not([class])"
15801615
else:
15811616
return
15821617
else:

seleniumbase/plugins/driver_manager.py

+17
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,23 @@ def Driver(
781781
swiftshader = False
782782
if locale is not None and locale_code is None:
783783
locale_code = locale
784+
if locale_code is None:
785+
if '--locale="' in arg_join:
786+
locale_code = (
787+
arg_join.split('--locale="')[1].split('"')[0]
788+
)
789+
elif '--locale=' in arg_join:
790+
locale_code = (
791+
arg_join.split('--locale=')[1].split(' ')[0]
792+
)
793+
elif '--locale-code="' in arg_join:
794+
locale_code = (
795+
arg_join.split('--locale-code="')[1].split('"')[0]
796+
)
797+
elif '--locale-code=' in arg_join:
798+
locale_code = (
799+
arg_join.split('--locale-code=')[1].split(' ')[0]
800+
)
784801
if ad_block is not None and ad_block_on is None:
785802
ad_block_on = ad_block
786803
if ad_block_on is None:

seleniumbase/plugins/sb_manager.py

+17
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,23 @@ def SB(
942942
swiftshader = False
943943
if locale is not None and locale_code is None:
944944
locale_code = locale
945+
if locale_code is None:
946+
if '--locale="' in arg_join:
947+
locale_code = (
948+
arg_join.split('--locale="')[1].split('"')[0]
949+
)
950+
elif '--locale=' in arg_join:
951+
locale_code = (
952+
arg_join.split('--locale=')[1].split(' ')[0]
953+
)
954+
elif '--locale-code="' in arg_join:
955+
locale_code = (
956+
arg_join.split('--locale-code="')[1].split('"')[0]
957+
)
958+
elif '--locale-code=' in arg_join:
959+
locale_code = (
960+
arg_join.split('--locale-code=')[1].split(' ')[0]
961+
)
945962
if ad_block is not None and ad_block_on is None:
946963
ad_block_on = ad_block
947964
if ad_block_on is None:

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
"certifi>=2025.1.31",
157157
"exceptiongroup>=1.2.2",
158158
'websockets~=13.1;python_version<"3.9"',
159-
'websockets>=15.0;python_version>="3.9"',
159+
'websockets>=15.0.1;python_version>="3.9"',
160160
'filelock~=3.16.1;python_version<"3.9"',
161161
'filelock>=3.17.0;python_version>="3.9"',
162162
'fasteners>=0.19',
@@ -167,7 +167,7 @@
167167
"sbvirtualdisplay>=1.4.0",
168168
'MarkupSafe==2.1.5;python_version<"3.9"',
169169
'MarkupSafe>=3.0.2;python_version>="3.9"',
170-
"Jinja2>=3.1.5",
170+
"Jinja2>=3.1.6",
171171
"six>=1.17.0",
172172
'parse>=1.20.2',
173173
'parse-type>=0.6.4',

0 commit comments

Comments
 (0)