Skip to content

Commit 50e8658

Browse files
committed
Update the UC Mode docs
1 parent 32a3450 commit 50e8658

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

help_docs/uc_mode.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
* Automatically setting various chromium args as needed.
2323
* Has special `uc_*()` methods.
2424

25-
👤 Here's an example with the <b><code translate="no">Driver</code></b> manager:
25+
👤 Here's a simple example with the <b><code translate="no">Driver</code></b> manager:
2626

2727
```python
2828
from seleniumbase import Driver
2929

3030
driver = Driver(uc=True)
3131
url = "https://gitlab.com/users/sign_in"
32-
driver.uc_open_with_reconnect(url, 3)
32+
driver.uc_open_with_reconnect(url, 4)
3333
driver.quit()
3434
```
3535

@@ -42,21 +42,22 @@ from seleniumbase import SB
4242

4343
with SB(uc=True) as sb:
4444
url = "https://gitlab.com/users/sign_in"
45-
sb.uc_open_with_reconnect(url, 3)
45+
sb.uc_open_with_reconnect(url, 4)
4646
```
4747

48-
👤 Here's a longer example, which includes a retry if the CAPTCHA isn't bypassed on the first attempt:
48+
👤 Here's a longer example, which includes a special click if the CAPTCHA isn't bypassed on the initial page load:
4949

5050
```python
5151
from seleniumbase import SB
5252

5353
with SB(uc=True, test=True) as sb:
5454
url = "https://gitlab.com/users/sign_in"
55-
sb.uc_open_with_reconnect(url, 3)
56-
if not sb.is_text_visible("Username", '[for="user_login"]'):
57-
sb.uc_open_with_reconnect(url, 4)
55+
sb.uc_open_with_reconnect(url, 4)
56+
sb.uc_gui_click_captcha()
5857
sb.assert_text("Username", '[for="user_login"]', timeout=3)
59-
sb.highlight('label[for="user_login"]', loops=3)
58+
sb.assert_element('label[for="user_login"]')
59+
sb.highlight('button:contains("Sign in")')
60+
sb.highlight('h1:contains("GitLab.com")')
6061
sb.post_message("SeleniumBase wasn't detected", duration=4)
6162
```
6263

@@ -78,21 +79,22 @@ with SB(uc=True, test=True) as sb:
7879

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

81-
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 reCAPTCHA.
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.
8283

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

8586
```python
8687
from seleniumbase import SB
8788

88-
with SB(uc=True, test=True, locale_code="en") as sb:
89+
with SB(uc=True, test=True, incognito=True, locale_code="en") as sb:
8990
url = "https://ahrefs.com/website-authority-checker"
9091
input_field = 'input[placeholder="Enter domain"]'
9192
submit_button = 'span:contains("Check Authority")'
92-
sb.uc_open_with_reconnect(url, 1) # The bot-check is later
93+
sb.uc_open_with_reconnect(url, 2) # The bot-check is later
9394
sb.type(input_field, "github.com/seleniumbase/SeleniumBase")
9495
sb.reconnect(0.1)
9596
sb.uc_click(submit_button, reconnect_time=4)
97+
sb.uc_gui_click_captcha()
9698
sb.wait_for_text_not_visible("Checking", timeout=10)
9799
sb.highlight('p:contains("github.com/seleniumbase/SeleniumBase")')
98100
sb.highlight('a:contains("Top 100 backlinks")')
@@ -109,13 +111,9 @@ from seleniumbase import SB
109111

110112
with SB(uc=True, test=True, ad_block=True) as sb:
111113
url = "https://www.thaiticketmajor.com/concert/"
112-
sb.uc_open_with_reconnect(url, 5.5)
113-
sb.uc_click("button.btn-signin", 4)
114-
sb.switch_to_frame('iframe[title*="Cloudflare"]')
115-
sb.assert_element("div#success svg#success-icon")
116-
sb.switch_to_default_content()
117-
sb.set_messenger_theme(location="top_center")
118-
sb.post_message("SeleniumBase wasn't detected!")
114+
sb.uc_open_with_reconnect(url, 6.111)
115+
sb.uc_click("button.btn-signin", 4.1)
116+
sb.uc_gui_click_captcha()
119117
```
120118

121119
<img src="https://seleniumbase.github.io/other/ttm_bypass.png" title="SeleniumBase" width="540">
@@ -235,7 +233,7 @@ driver.reconnect("breakpoint")
235233

236234
(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>.)
237235

238-
👤 On Linux, you may need to use `driver.uc_gui_click_cf()` to successfully bypass a Cloudflare CAPTCHA. If there's more than one iframe on that website (and Cloudflare isn't the first one) then put the CSS Selector of that 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.
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.
239237

240238
👤 `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.
241239

@@ -334,6 +332,16 @@ The above JS method is used within the <b><code translate="no">SeleniumBase</cod
334332

335333
--------
336334

335+
🛠️ <b>Troubleshooting UC Mode</b>
336+
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.)
338+
339+
<img src="https://seleniumbase.github.io/other/ts_uc_1.jpg" title="Make sure Scaling is set to 100%" width="410">
340+
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`.
342+
343+
--------
344+
337345
🏆 <b>Choosing the right CAPTCHA service</b> for your business / website:
338346

339347
<img src="https://seleniumbase.github.io/other/me_se_conf.jpg" title="SeleniumBase" width="370">

0 commit comments

Comments
 (0)