Skip to content

Make UC Mode more advanced #2919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 8, 2024
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
9 changes: 9 additions & 0 deletions examples/raw_recaptcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/apps/recaptcha"
sb.uc_open_with_reconnect(url)
sb.uc_gui_click_captcha()
sb.assert_element("img#captcha-success", timeout=3)
sb.set_messenger_theme(location="top_left")
sb.post_message("SeleniumBase wasn't detected", duration=3)
6 changes: 3 additions & 3 deletions examples/raw_turnstile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "seleniumbase.io/apps/turnstile"
sb.uc_open_with_reconnect(url, reconnect_time=2)
sb.uc_gui_handle_cf()
url = "https://seleniumbase.io/apps/turnstile"
sb.uc_open_with_reconnect(url)
sb.uc_gui_click_captcha()
sb.assert_element("img#captcha-success", timeout=3)
sb.set_messenger_theme(location="top_left")
sb.post_message("SeleniumBase wasn't detected", duration=3)
2 changes: 1 addition & 1 deletion examples/raw_uc_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
with SB(uc=True, test=True) as sb:
url = "https://gitlab.com/users/sign_in"
sb.uc_open_with_reconnect(url, 4)
sb.uc_gui_click_cf()
sb.uc_gui_click_captcha()
sb.assert_text("Username", '[for="user_login"]', timeout=3)
sb.assert_element('label[for="user_login"]')
sb.highlight('button:contains("Sign in")')
Expand Down
6 changes: 5 additions & 1 deletion help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,11 @@ driver.uc_gui_write(text) # Similar to uc_gui_press_keys(), but faster

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

driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False) # (*)
driver.uc_gui_click_captcha(frame="iframe", retry=False, blind=False)

driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False) # reC

driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False) # CFT

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

Expand Down
12 changes: 10 additions & 2 deletions help_docs/uc_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ with SB(uc=True, test=True) as sb:
from seleniumbase import SB

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

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

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

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

Expand Down Expand Up @@ -192,6 +192,10 @@ driver.uc_gui_write(text)

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

driver.uc_gui_click_captcha(frame="iframe", retry=False, blind=False)

driver.uc_gui_click_rc(frame="iframe", retry=False, blind=False)

driver.uc_gui_click_cf(frame="iframe", retry=False, blind=False)

driver.uc_gui_handle_cf(frame="iframe")
Expand Down Expand Up @@ -235,6 +239,10 @@ driver.reconnect("breakpoint")

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

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

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

👤 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:

```python
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pip>=24.0;python_version<"3.8"
pip>=24.1.1;python_version>="3.8"
pip>=24.1.2;python_version>="3.8"
packaging>=24.0;python_version<"3.8"
packaging>=24.1;python_version>="3.8"
setuptools>=68.0.0;python_version<"3.8"
Expand All @@ -21,8 +21,8 @@ six==1.16.0
idna==3.7
chardet==5.2.0
charset-normalizer==3.3.2
urllib3>=1.26.18,<2;python_version<"3.10"
urllib3>=1.26.18,<2.3.0;python_version>="3.10"
urllib3>=1.26.19,<2;python_version<"3.10"
urllib3>=1.26.19,<2.3.0;python_version>="3.10"
requests==2.31.0
pynose==1.5.1
sniffio==1.3.1
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.28.4"
__version__ = "4.28.5"
Loading