Skip to content

Commit e8c2147

Browse files
authored
Merge pull request #2987 from seleniumbase/update-mobile-mode-and-uc-mode
Update Mobile Mode and UC Mode
2 parents 97ab360 + a4355f0 commit e8c2147

File tree

12 files changed

+156
-98
lines changed

12 files changed

+156
-98
lines changed

examples/raw_cdp_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
try:
66
url = "seleniumbase.io/apps/turnstile"
77
driver.uc_open_with_reconnect(url, 2)
8-
driver.uc_gui_handle_cf()
8+
driver.uc_gui_handle_captcha()
99
driver.sleep(3)
1010
pprint(driver.get_log("performance"))
1111
finally:

examples/raw_form_turnstile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
sb.highlight_click('input[value="AR"] + span')
1414
sb.click('input[value="cc"] + span')
1515
sb.scroll_to('div[class*="cf-turnstile"]')
16-
sb.uc_gui_handle_cf()
16+
sb.uc_gui_handle_captcha()
1717
sb.highlight("img#captcha-success", timeout=3)
1818
sb.highlight_click('button:contains("Request & Pay")')
1919
sb.highlight("img#submit-success")

examples/raw_gui_click.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
"""
2-
UC Mode now has uc_gui_click_cf(), which uses PyAutoGUI.
3-
An incomplete UserAgent forces CAPTCHA-solving on macOS.
4-
"""
51
import sys
62
from seleniumbase import SB
73

4+
# An incomplete UserAgent forces CAPTCHA-solving on macOS
85
agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/126.0.0.0"
96
if "linux" in sys.platform or "win32" in sys.platform:
107
agent = None # Use the default UserAgent
118

129
with SB(uc=True, test=True, rtf=True, agent=agent) as sb:
1310
url = "https://gitlab.com/users/sign_in"
1411
sb.uc_open_with_reconnect(url, 4)
15-
sb.uc_gui_click_cf() # Ready if needed!
12+
sb.uc_gui_click_captcha() # Only if needed
1613
sb.assert_element('label[for="user_login"]')
1714
sb.assert_element('input[data-testid*="username"]')
1815
sb.assert_element('input[data-testid*="password"]')

examples/raw_pyautogui.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
"""
2-
UC Mode now has uc_gui_handle_cf(), which uses PyAutoGUI.
3-
An incomplete User-Agent forces CAPTCHA-solving on macOS.
4-
"""
51
import sys
62
from seleniumbase import SB
73

4+
# An incomplete UserAgent forces CAPTCHA-solving on macOS
85
agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/126.0.0.0"
96
if "linux" in sys.platform or "win32" in sys.platform:
107
agent = None # Use the default UserAgent
118

129
with SB(uc=True, test=True, rtf=True, agent=agent) as sb:
1310
url = "https://gitlab.com/users/sign_in"
1411
sb.uc_open_with_reconnect(url, 4)
15-
sb.uc_gui_handle_cf() # Ready if needed!
12+
sb.uc_gui_handle_captcha() # Only if needed
1613
sb.assert_element('label[for="user_login"]')
1714
sb.assert_element('input[data-testid*="username"]')
1815
sb.assert_element('input[data-testid*="password"]')

examples/raw_recaptcha.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
with SB(uc=True, test=True) as sb:
44
url = "https://seleniumbase.io/apps/recaptcha"
55
sb.uc_open_with_reconnect(url)
6-
sb.uc_gui_click_captcha()
6+
sb.uc_gui_handle_captcha() # Try with TAB + SPACEBAR
7+
sb.assert_element("img#captcha-success", timeout=3)
8+
sb.set_messenger_theme(location="top_left")
9+
sb.post_message("SeleniumBase wasn't detected", duration=3)
10+
11+
with SB(uc=True, test=True) as sb:
12+
url = "https://seleniumbase.io/apps/recaptcha"
13+
sb.uc_open_with_reconnect(url)
14+
sb.uc_gui_click_captcha() # Try with PyAutoGUI Click
715
sb.assert_element("img#captcha-success", timeout=3)
816
sb.set_messenger_theme(location="top_left")
917
sb.post_message("SeleniumBase wasn't detected", duration=3)

examples/uc_cdp_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def add_cdp_listener(self):
1313
)
1414

1515
def click_turnstile_and_verify(sb):
16-
sb.uc_gui_handle_cf()
16+
sb.uc_gui_handle_captcha()
1717
sb.assert_element("img#captcha-success", timeout=3)
1818
sb.highlight("img#captcha-success", loops=8)
1919

help_docs/method_summary.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,12 +1077,12 @@ driver.uc_gui_write(text) # Similar to uc_gui_press_keys(), but faster
10771077
driver.uc_gui_click_x_y(x, y, timeframe=0.25) # PyAutoGUI click screen
10781078

10791079
driver.uc_gui_click_captcha(frame="iframe", retry=False, blind=False)
1080+
# driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False)
1081+
# driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False)
10801082

1081-
driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False) # reC
1082-
1083-
driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False) # CFT
1084-
1085-
driver.uc_gui_handle_cf(frame="iframe") # PyAutoGUI click CF Turnstile
1083+
driver.uc_gui_handle_captcha(frame="iframe") # (Auto-detects the CAPTCHA)
1084+
# driver.uc_gui_handle_cf(frame="iframe") # PyAutoGUI click CF Turnstile
1085+
# driver.uc_gui_handle_rc(frame="iframe") # PyAutoGUI click G. reCAPTCHA
10861086

10871087
driver.uc_switch_to_frame(frame="iframe") # Stealthy switch_to_frame()
10881088
```

help_docs/uc_mode.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ with SB(uc=True) as sb:
4545
sb.uc_open_with_reconnect(url, 4)
4646
```
4747

48-
👤 Here's a longer example, which includes a special click if the CAPTCHA isn't bypassed on the initial page load:
48+
(Note: If running UC Mode scripts on headless Linux machines, then you'll need to use the <b><code translate="no">SB</code></b> manager instead of the <b><code translate="no">Driver</code></b> manager because the <b><code translate="no">SB</code></b> manager includes a special virtual display that allows for <b><code translate="no">PyAutoGUI</code></b> actions.)
49+
50+
👤 Here's a longer example, which includes a special <b><code translate="no">PyAutoGUI</code></b> click if the CAPTCHA isn't bypassed on the initial page load:
4951

5052
```python
5153
from seleniumbase import SB
@@ -71,15 +73,15 @@ from seleniumbase import SB
7173
with SB(uc=True, test=True) as sb:
7274
url = "https://seleniumbase.io/apps/turnstile"
7375
sb.uc_open_with_reconnect(url, reconnect_time=2)
74-
sb.uc_gui_handle_cf()
76+
sb.uc_gui_handle_captcha()
7577
sb.assert_element("img#captcha-success", timeout=3)
7678
sb.set_messenger_theme(location="top_left")
7779
sb.post_message("SeleniumBase wasn't detected", duration=3)
7880
```
7981

8082
<img src="https://seleniumbase.github.io/other/turnstile_click.jpg" title="SeleniumBase" width="440">
8183

82-
If running on a Linux server, `uc_gui_handle_cf()` might not be good enough. Switch to `uc_gui_click_cf()` to be more stealthy. You can also use `uc_gui_click_captcha()` as a generic CAPTCHA-clicker, which auto-detects between CF Turnstile and Google reCAPTCHA.
84+
If running on a Linux server, `uc_gui_handle_captcha()` might not be good enough. Switch to `uc_gui_click_captcha()` to be more stealthy. Note that these methods auto-detect between CF Turnstile and Google reCAPTCHA.
8385

8486
👤 Here's an example <b>where the CAPTCHA appears after submitting a form</b>:
8587

@@ -118,7 +120,7 @@ with SB(uc=True, test=True, ad_block=True) as sb:
118120

119121
<img src="https://seleniumbase.github.io/other/ttm_bypass.png" title="SeleniumBase" width="540">
120122

121-
👤 <b>On Linux</b>, use `sb.uc_gui_click_cf()` to handle Cloudflare Turnstiles:
123+
👤 <b>On Linux</b>, use `sb.uc_gui_click_captcha()` to handle CAPTCHAs (Cloudflare Turnstiles):
122124

123125
```python
124126
from seleniumbase import SB
@@ -127,15 +129,15 @@ with SB(uc=True, test=True) as sb:
127129
url = "https://www.virtualmanager.com/en/login"
128130
sb.uc_open_with_reconnect(url, 4)
129131
print(sb.get_page_title())
130-
sb.uc_gui_click_cf() # Ready if needed!
132+
sb.uc_gui_click_captcha() # Only if needed
131133
print(sb.get_page_title())
132134
sb.assert_element('input[name*="email"]')
133135
sb.assert_element('input[name*="login"]')
134136
sb.set_messenger_theme(location="bottom_center")
135137
sb.post_message("SeleniumBase wasn't detected!")
136138
```
137139

138-
<a href="https://github.com/mdmintz/undetected-testing/actions/runs/9637461606/job/26576722411"><img width="540" alt="uc_gui_click_cf on Linux" src="https://github.com/seleniumbase/SeleniumBase/assets/6788579/6aceb2a3-2a32-4521-b30a-f79446d2ce28"></a>
140+
<a href="https://github.com/mdmintz/undetected-testing/actions/runs/9637461606/job/26576722411"><img width="540" alt="uc_gui_click_captcha on Linux" src="https://github.com/seleniumbase/SeleniumBase/assets/6788579/6aceb2a3-2a32-4521-b30a-f79446d2ce28"></a>
139141

140142
The 2nd `print()` should output "Virtual Manager", which means that the automation successfully passed the Turnstile.
141143

@@ -191,12 +193,12 @@ driver.uc_gui_write(text)
191193
driver.uc_gui_click_x_y(x, y, timeframe=0.25)
192194

193195
driver.uc_gui_click_captcha(frame="iframe", retry=False, blind=False)
196+
# driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False)
197+
# driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False)
194198

195-
driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False)
196-
197-
driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False)
198-
199-
driver.uc_gui_handle_cf(frame="iframe")
199+
driver.uc_gui_handle_captcha(frame="iframe")
200+
# driver.uc_gui_handle_cf(frame="iframe")
201+
# driver.uc_gui_handle_rc(frame="iframe")
200202

201203
driver.uc_switch_to_frame(frame, reconnect_time=None)
202204
```
@@ -233,14 +235,14 @@ driver.reconnect("breakpoint")
233235

234236
(Note that while the special <b><code translate="no">UC Mode</code></b> breakpoint is active, you can't use <b><code translate="no">Selenium</code></b> commands in the browser, and the browser can't detect <b><code translate="no">Selenium</code></b>.)
235237

236-
👤 On Linux, you may need to use `driver.uc_gui_click_cf()` to successfully bypass a Cloudflare CAPTCHA. If there's more than one Cloudflare iframe on that website, then put the CSS Selector of an element that's above the iframe as the first arg to `driver.uc_gui_click_cf()`. This method uses `pyautogui`. In order for `pyautogui` to focus on the correct element, use `xvfb=True` / `--xvfb` to activate a special virtual display on Linux.
238+
👤 On Linux, you may need to use `driver.uc_gui_click_captcha()` to successfully bypass a Cloudflare CAPTCHA. If there's more than one Cloudflare iframe on that website, then put the CSS Selector of an element that's above the iframe as the first arg to `driver.uc_gui_click_captcha()`. This method uses `pyautogui`. In order for `pyautogui` to focus on the correct element, use `xvfb=True` / `--xvfb` to activate a special virtual display on Linux.
239+
240+
👤 `driver.uc_gui_click_captcha()` auto-detects the CAPTCHA type before trying to click it. This is a generic method for both CF Turnstile and Google reCAPTCHA. It will use the code from `uc_gui_click_cf()` and `uc_gui_click_rc()` as needed.
237241

238242
👤 `driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False)` has three args. (All optional). The first one, `frame`, lets you specify the iframe in case the CAPTCHA is not located in the first iframe on the page. The second one, `retry`, lets you retry the click after reloading the page if the first one didn't work (and a CAPTCHA is still present after the page reload). The third arg, `blind`, will retry after a page reload (if the first click failed) by clicking at the last known coordinates of the CAPTCHA checkbox without confirming first with Selenium that a CAPTCHA is still on the page.
239243

240244
👤 `driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False)` is for reCAPTCHA. This may only work a few times before not working anymore... not because Selenium was detected, but because reCAPTCHA uses advanced AI to detect unusual activity, unlike the CF Turnstile, which only uses basic detection.
241245

242-
👤 `driver.uc_gui_click_captcha()` auto-detects the CAPTCHA type before trying to click it. This is a generic method for both CF Turnstile and Google reCAPTCHA. It will use the code from `uc_gui_click_cf()` and `uc_gui_click_rc()` as needed.
243-
244246
👤 To find out if <b translate="no">UC Mode</b> will work at all on a specific site (before adjusting for timing), load your site with the following script:
245247

246248
```python
@@ -334,11 +336,11 @@ The above JS method is used within the <b><code translate="no">SeleniumBase</cod
334336

335337
🛠️ <b>Troubleshooting UC Mode</b>
336338

337-
On Windows, the `uc_gui_click_cf()` and `uc_gui_click_captcha()` methods require "Scaling" to be set at "100%". (Note that "100%" may be different from the system's "Recommended" percent, which can be higher depending on your screen resolution and monitor size.)
339+
On Windows, the `uc_gui_click_captcha()` method requires "Scaling" to be set at "100%". (Note that "100%" may be different from the system's "Recommended" percent, which can be higher depending on your screen resolution and monitor size.)
338340

339341
<img src="https://seleniumbase.github.io/other/ts_uc_1.jpg" title="Make sure Scaling is set to 100%" width="410">
340342

341-
As an alternative to using the `uc_gui_click_cf()` or `uc_gui_click_captcha()` methods on Windows, you can use `sb.uc_gui_handle_cf()`, which does not require "Scaling" to be set to a specific value. Instead of using the mouse to click a CAPTCHA, `sb.uc_gui_handle_cf()` uses a combination of the `TAB` key and the `SPACEBAR`.
343+
As an alternative to using the `uc_gui_click_captcha()` method on Windows, you can use `sb.uc_gui_handle_captcha()`, which does not require "Scaling" to be set to a specific value. Instead of using the mouse to click a CAPTCHA, `sb.uc_gui_handle_captcha()` uses a combination of the `TAB` key and the `SPACEBAR`.
342344

343345
--------
344346

mkdocs_build/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ lxml==5.2.2
2020
pyquery==2.0.0
2121
readtime==3.0.0
2222
mkdocs==1.6.0
23-
mkdocs-material==9.5.30
23+
mkdocs-material==9.5.31
2424
mkdocs-exclude-search==0.6.6
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.3.1

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.29.4"
2+
__version__ = "4.29.5"

0 commit comments

Comments
 (0)