Skip to content

Commit f65a302

Browse files
authored
Merge pull request #2919 from seleniumbase/advanced-uc-mode
Make UC Mode more advanced
2 parents 620b53e + 59602bd commit f65a302

File tree

10 files changed

+237
-54
lines changed

10 files changed

+237
-54
lines changed

examples/raw_recaptcha.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True) as sb:
4+
url = "https://seleniumbase.io/apps/recaptcha"
5+
sb.uc_open_with_reconnect(url)
6+
sb.uc_gui_click_captcha()
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)

examples/raw_turnstile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from seleniumbase import SB
22

33
with SB(uc=True, test=True) as sb:
4-
url = "seleniumbase.io/apps/turnstile"
5-
sb.uc_open_with_reconnect(url, reconnect_time=2)
6-
sb.uc_gui_handle_cf()
4+
url = "https://seleniumbase.io/apps/turnstile"
5+
sb.uc_open_with_reconnect(url)
6+
sb.uc_gui_click_captcha()
77
sb.assert_element("img#captcha-success", timeout=3)
88
sb.set_messenger_theme(location="top_left")
99
sb.post_message("SeleniumBase wasn't detected", duration=3)

examples/raw_uc_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
with SB(uc=True, test=True) as sb:
55
url = "https://gitlab.com/users/sign_in"
66
sb.uc_open_with_reconnect(url, 4)
7-
sb.uc_gui_click_cf()
7+
sb.uc_gui_click_captcha()
88
sb.assert_text("Username", '[for="user_login"]', timeout=3)
99
sb.assert_element('label[for="user_login"]')
1010
sb.highlight('button:contains("Sign in")')

help_docs/method_summary.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,11 @@ driver.uc_gui_write(text) # Similar to uc_gui_press_keys(), but faster
10761076

10771077
driver.uc_gui_click_x_y(x, y, timeframe=0.25) # PyAutoGUI click screen
10781078

1079-
driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False) # (*)
1079+
driver.uc_gui_click_captcha(frame="iframe", retry=False, blind=False)
1080+
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
10801084

10811085
driver.uc_gui_handle_cf(frame="iframe") # PyAutoGUI click CF Turnstile
10821086

help_docs/uc_mode.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ with SB(uc=True, test=True) as sb:
6868
from seleniumbase import SB
6969

7070
with SB(uc=True, test=True) as sb:
71-
url = "seleniumbase.io/apps/turnstile"
71+
url = "https://seleniumbase.io/apps/turnstile"
7272
sb.uc_open_with_reconnect(url, reconnect_time=2)
7373
sb.uc_gui_handle_cf()
7474
sb.assert_element("img#captcha-success", timeout=3)
@@ -78,7 +78,7 @@ with SB(uc=True, test=True) as sb:
7878

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

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.
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.
8282

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

@@ -192,6 +192,10 @@ driver.uc_gui_write(text)
192192

193193
driver.uc_gui_click_x_y(x, y, timeframe=0.25)
194194

195+
driver.uc_gui_click_captcha(frame="iframe", retry=False, blind=False)
196+
197+
driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False)
198+
195199
driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False)
196200

197201
driver.uc_gui_handle_cf(frame="iframe")
@@ -235,6 +239,10 @@ driver.reconnect("breakpoint")
235239

236240
👤 `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.
237241

242+
👤 `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.
243+
244+
👤 `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.
245+
238246
👤 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:
239247

240248
```python

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pip>=24.0;python_version<"3.8"
2-
pip>=24.1.1;python_version>="3.8"
2+
pip>=24.1.2;python_version>="3.8"
33
packaging>=24.0;python_version<"3.8"
44
packaging>=24.1;python_version>="3.8"
55
setuptools>=68.0.0;python_version<"3.8"
@@ -21,8 +21,8 @@ six==1.16.0
2121
idna==3.7
2222
chardet==5.2.0
2323
charset-normalizer==3.3.2
24-
urllib3>=1.26.18,<2;python_version<"3.10"
25-
urllib3>=1.26.18,<2.3.0;python_version>="3.10"
24+
urllib3>=1.26.19,<2;python_version<"3.10"
25+
urllib3>=1.26.19,<2.3.0;python_version>="3.10"
2626
requests==2.31.0
2727
pynose==1.5.1
2828
sniffio==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.28.4"
2+
__version__ = "4.28.5"

0 commit comments

Comments
 (0)