Skip to content

Commit 0fb6618

Browse files
authored
Merge pull request #2866 from seleniumbase/big-uc-mode-updates-and-more
Lots of UC Mode improvements, and more
2 parents 3bb813f + c197397 commit 0fb6618

27 files changed

+743
-200
lines changed

examples/raw_antibot_login.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""UC Mode has PyAutoGUI methods for CAPTCHA-bypass."""
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True) as sb:
5+
url = "https://seleniumbase.io/antibot/login"
6+
sb.uc_open_with_disconnect(url, 2.15)
7+
sb.uc_gui_write("\t" + "demo_user")
8+
sb.uc_gui_write("\t" + "secret_pass")
9+
sb.uc_gui_press_keys("\t" + " ") # For Single-char keys
10+
sb.sleep(1.5)
11+
sb.uc_gui_press_keys(["\t", "ENTER"]) # Multi-char keys
12+
sb.reconnect(1.8)
13+
sb.assert_text("Welcome!", "h1")
14+
sb.set_messenger_theme(location="bottom_center")
15+
sb.post_message("SeleniumBase wasn't detected!")

examples/raw_block.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""If Brotector catches you, Gandalf blocks you!"""
2+
from seleniumbase import SB
3+
4+
with SB(test=True) as sb:
5+
url = "https://seleniumbase.io/hobbit/login"
6+
sb.open(url)
7+
sb.click_if_visible("button")
8+
sb.assert_text("Gandalf blocked you!", "h1")
9+
sb.click("img")
10+
sb.highlight("h1")
11+
sb.sleep(3) # Gandalf: "You Shall Not Pass!"

examples/raw_brotector_captcha.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""UC Mode has PyAutoGUI methods for CAPTCHA-bypass."""
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True) as sb:
5+
url = "https://seleniumbase.io/apps/brotector"
6+
sb.uc_open_with_disconnect(url, 2.2)
7+
sb.uc_gui_press_key("\t")
8+
sb.uc_gui_press_key(" ")
9+
sb.reconnect(2.2)

examples/raw_detection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""The Brotector CAPTCHA in action."""
2+
from seleniumbase import SB
3+
4+
with SB(test=True) as sb:
5+
sb.open("https://seleniumbase.io/antibot/login")
6+
sb.highlight("h4", loops=6)
7+
sb.type("#username", "demo_user")
8+
sb.type("#password", "secret_pass")
9+
sb.click_if_visible("button span")
10+
sb.highlight("label#pText")
11+
sb.highlight("table#detections")
12+
sb.sleep(4.4) # Add time to read the table

examples/raw_hobbit.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""UC Mode has PyAutoGUI methods for CAPTCHA-bypass."""
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True) as sb:
5+
url = "https://seleniumbase.io/hobbit/login"
6+
sb.uc_open_with_disconnect(url, 2.2)
7+
sb.uc_gui_press_keys("\t ")
8+
sb.reconnect(1.5)
9+
sb.assert_text("Welcome to Middle Earth!", "h1")
10+
sb.set_messenger_theme(location="bottom_center")
11+
sb.post_message("SeleniumBase wasn't detected!")
12+
sb.click("img")
13+
sb.sleep(5.888) # Cool animation happening now!

examples/raw_pyautogui.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
UC Mode now has uc_gui_handle_cf(), which uses PyAutoGUI.
3+
An incomplete UserAgent is used to force CAPTCHA-solving.
4+
"""
5+
import sys
6+
from seleniumbase import SB
7+
8+
agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/126.0.0.0"
9+
if "linux" in sys.platform:
10+
agent = None # Use the default UserAgent
11+
12+
with SB(uc=True, test=True, rtf=True, agent=agent) as sb:
13+
url = "https://www.virtualmanager.com/en/login"
14+
sb.uc_open_with_reconnect(url, 4)
15+
sb.uc_gui_handle_cf() # Ready if needed!
16+
sb.assert_element('input[name*="email"]')
17+
sb.assert_element('input[name*="login"]')
18+
sb.set_messenger_theme(location="bottom_center")
19+
sb.post_message("SeleniumBase wasn't detected!")

help_docs/method_summary.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ self.click_partial_link(partial_link_text, timeout=None)
111111
# Duplicates:
112112
# self.click_partial_link_text(partial_link_text, timeout=None)
113113

114-
self.get_text(selector, by="css selector", timeout=None)
114+
self.get_text(selector="html", by="css selector", timeout=None)
115115

116116
self.get_attribute(selector, attribute, by="css selector", timeout=None, hard_fail=True)
117117

@@ -127,7 +127,7 @@ self.remove_attributes(selector, attribute, by="css selector")
127127

128128
self.get_property(selector, property, by="css selector", timeout=None)
129129

130-
self.get_text_content(selector, by="css selector", timeout=None)
130+
self.get_text_content(selector="html", by="css selector", timeout=None)
131131

132132
self.get_property_value(selector, property, by="css selector", timeout=None)
133133

@@ -229,7 +229,7 @@ self.set_window_size(width, height)
229229

230230
self.maximize_window()
231231

232-
self.switch_to_frame(frame, timeout=None)
232+
self.switch_to_frame(frame="iframe", timeout=None)
233233

234234
self.switch_to_default_content()
235235

@@ -1032,7 +1032,7 @@ driver.get_page_source()
10321032

10331033
driver.get_title()
10341034

1035-
driver.switch_to_frame(frame)
1035+
driver.switch_to_frame(frame="iframe")
10361036

10371037
############
10381038

@@ -1046,7 +1046,7 @@ driver.uc_open_with_tab(url) # (New tab with default reconnect_time)
10461046

10471047
driver.uc_open_with_reconnect(url, reconnect_time=None) # (New tab)
10481048

1049-
driver.uc_open_with_disconnect(url) # Open in new tab + disconnect()
1049+
driver.uc_open_with_disconnect(url, timeout=None) # New tab + sleep()
10501050

10511051
driver.reconnect(timeout) # disconnect() + sleep(timeout) + connect()
10521052

@@ -1056,7 +1056,15 @@ driver.connect() # Starts the webdriver service to allow actions again
10561056

10571057
driver.uc_click(selector) # A stealthy click for evading bot-detection
10581058

1059-
driver.uc_switch_to_frame(frame) # switch_to_frame() in a stealthy way
1059+
driver.uc_gui_press_key(key) # Use PyAutoGUI to press the keyboard key
1060+
1061+
driver.uc_gui_press_keys(keys) # Use PyAutoGUI to press a list of keys
1062+
1063+
driver.uc_gui_write(text) # Similar to uc_gui_press_keys(), but faster
1064+
1065+
driver.uc_gui_handle_cf(frame="iframe") # PyAutoGUI click CF Turnstile
1066+
1067+
driver.uc_switch_to_frame(frame="iframe") # Stealthy switch_to_frame()
10601068
```
10611069

10621070
--------

help_docs/uc_mode.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ driver.uc_open_with_tab(url)
159159

160160
driver.uc_open_with_reconnect(url, reconnect_time=None)
161161

162-
driver.uc_open_with_disconnect(url)
162+
driver.uc_open_with_disconnect(url, timeout=None)
163163

164164
driver.reconnect(timeout)
165165

@@ -171,6 +171,14 @@ driver.uc_click(
171171
selector, by="css selector",
172172
timeout=settings.SMALL_TIMEOUT, reconnect_time=None)
173173

174+
driver.uc_gui_press_key(key)
175+
176+
driver.uc_gui_press_keys(keys)
177+
178+
driver.uc_gui_write(text)
179+
180+
driver.uc_gui_handle_cf(frame="iframe")
181+
174182
driver.uc_switch_to_frame(frame, reconnect_time=None)
175183
```
176184

@@ -211,6 +219,8 @@ driver.reconnect("breakpoint")
211219
<li>Timing. (<b translate="no">UC Mode</b> methods let you customize default values that aren't good enough for your environment.)</li>
212220
<li>Not using <b><code translate="no">driver.uc_click(selector)</code></b> when you need to remain undetected while clicking something.</li>
213221

222+
👤 On Linux, you may need to use `driver.uc_gui_handle_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_handle_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.
223+
214224
👤 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:
215225

216226
```python

mkdocs_build/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
regex>=2024.5.15
55
pymdown-extensions>=10.8.1
6-
pipdeptree>=2.22.0
6+
pipdeptree>=2.23.0
77
python-dateutil>=2.8.2
88
Markdown==3.6
99
markdown2==2.4.13
@@ -12,15 +12,15 @@ Jinja2==3.1.4
1212
click==8.1.7
1313
ghp-import==2.1.0
1414
watchdog==4.0.1
15-
cairocffi==1.7.0
15+
cairocffi==1.7.1
1616
pathspec==0.12.1
1717
Babel==2.15.0
1818
paginate==0.5.6
1919
lxml==5.2.2
2020
pyquery==2.0.0
2121
readtime==3.0.0
2222
mkdocs==1.6.0
23-
mkdocs-material==9.5.26
23+
mkdocs-material==9.5.27
2424
mkdocs-exclude-search==0.6.6
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.3.1

requirements.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
pip>=24.0
2-
packaging>=24.0
1+
pip>=24.0;python_version<"3.8"
2+
pip>=24.1;python_version>="3.8"
3+
packaging>=24.0;python_version<"3.8"
4+
packaging>=24.1;python_version>="3.8"
35
setuptools>=68.0.0;python_version<"3.8"
4-
setuptools>=70.0.0;python_version>="3.8"
6+
setuptools>=70.1.0;python_version>="3.8"
57
wheel>=0.42.0;python_version<"3.8"
68
wheel>=0.43.0;python_version>="3.8"
79
attrs>=23.2.0
810
certifi>=2024.6.2
911
exceptiongroup>=1.2.1
1012
filelock>=3.12.2;python_version<"3.8"
11-
filelock>=3.14.0;python_version>="3.8"
13+
filelock>=3.15.4;python_version>="3.8"
1214
platformdirs>=4.0.0;python_version<"3.8"
1315
platformdirs>=4.2.2;python_version>="3.8"
1416
typing-extensions>=4.12.2;python_version>="3.8"
15-
parse>=1.20.1
17+
parse>=1.20.2
1618
parse-type>=0.6.2
1719
pyyaml>=6.0.1
1820
six==1.16.0
@@ -30,8 +32,9 @@ trio==0.22.2;python_version<"3.8"
3032
trio==0.25.1;python_version>="3.8"
3133
trio-websocket==0.11.1
3234
wsproto==1.2.0
35+
websocket-client==1.8.0;python_version>="3.8"
3336
selenium==4.11.2;python_version<"3.8"
34-
selenium==4.21.0;python_version>="3.8"
37+
selenium==4.22.0;python_version>="3.8"
3538
cssselect==1.2.0
3639
sortedcontainers==2.4.0
3740
fasteners==0.19
@@ -64,6 +67,7 @@ tabcompleter==1.3.0
6467
pdbp==1.5.0
6568
colorama==0.4.6
6669
pyotp==2.9.0
70+
python-xlib==0.33;platform_system=="Linux"
6771
markdown-it-py==2.2.0;python_version<"3.8"
6872
markdown-it-py==3.0.0;python_version>="3.8"
6973
mdurl==0.1.2
@@ -73,13 +77,13 @@ rich==13.7.1
7377
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)
7478

7579
coverage==7.2.7;python_version<"3.8"
76-
coverage>=7.5.3;python_version>="3.8"
80+
coverage>=7.5.4;python_version>="3.8"
7781
pytest-cov==4.1.0;python_version<"3.8"
7882
pytest-cov>=5.0.0;python_version>="3.8"
7983
flake8==5.0.4;python_version<"3.9"
80-
flake8==7.0.0;python_version>="3.9"
84+
flake8==7.1.0;python_version>="3.9"
8185
mccabe==0.7.0
8286
pyflakes==2.5.0;python_version<"3.9"
8387
pyflakes==3.2.0;python_version>="3.9"
8488
pycodestyle==2.9.1;python_version<"3.9"
85-
pycodestyle==2.11.1;python_version>="3.9"
89+
pycodestyle==2.12.0;python_version>="3.9"

0 commit comments

Comments
 (0)