Skip to content

Commit

Permalink
Merge pull request #3094 from seleniumbase/update-uc-mode-and-examples
Browse files Browse the repository at this point in the history
Update UC Mode and examples
  • Loading branch information
mdmintz authored Sep 5, 2024
2 parents aed62a4 + 8686812 commit 4c745d2
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 112 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@
<br />
</p>

<p>SeleniumBase is the professional toolkit for web automation activities. Built for testing websites, bypassing CAPTCHAs, enhancing productivity, completing tasks, and scaling your business.</p>

--------

📚 Learn from [**over 200 examples** in the **SeleniumBase/examples/** folder](https://github.com/seleniumbase/SeleniumBase/tree/master/examples).

👤 Note that <span translate="no">SeleniumBase</span> <a translate="no" href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md"><b>UC Mode</b> (Stealth Mode) has its own ReadMe</a>.

ℹ️ Scripts can be called via <code translate="no"><b>python</b></code>, although some <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a> expect <a href="https://docs.pytest.org/en/latest/how-to/usage.html" translate="no"><b>pytest</b></a> (a Python unit-testing framework included with SeleniumBase that can discover & collect tests automatically).
ℹ️ Scripts can be called via <code translate="no"><b>python</b></code>, although some <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a> expect <a href="https://docs.pytest.org/en/latest/how-to/usage.html" translate="no"><b>pytest</b></a> (a Python unit-testing framework included with SeleniumBase that can discover, collect, and run tests automatically).

<p align="left">📗 Here's <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py">my_first_test.py</a>, which tests login, shopping, and checkout:</p>

Expand Down
21 changes: 10 additions & 11 deletions examples/presenter/uc_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def test_presentation(self):
self.get_new_driver(undetectable=True)
url = "https://gitlab.com/users/sign_in"
try:
self.driver.uc_open_with_reconnect(url, reconnect_time=3)
self.uc_open_with_reconnect(url, reconnect_time=3)
try:
self.assert_text("Username", '[for="user_login"]', timeout=3)
self.post_message("SeleniumBase wasn't detected", duration=4)
except Exception:
self.driver.uc_open_with_reconnect(url, reconnect_time=4)
self.uc_open_with_reconnect(url, reconnect_time=4)
self.assert_text("Username", '[for="user_login"]', timeout=3)
self.post_message("SeleniumBase wasn't detected", duration=4)
finally:
Expand Down Expand Up @@ -249,8 +249,7 @@ def test_presentation(self):
code=(
"<mk-1>from seleniumbase import SB</mk-1>\n\n"
"<mk-2>with SB(uc=True) as sb:</mk-2>\n"
' <mk-3>sb.driver.get('
'"https://seleniumbase.io/simple/login")</mk-3>\n'
' <mk-3>sb.get("seleniumbase.io/simple/login")</mk-3>\n'
' <mk-4>sb.type("#username", "demo_user")</mk-4>\n'
' <mk-5>sb.type("#password", "secret_pass")</mk-5>\n'
' <mk-6>sb.click(\'a:contains("Sign in")\')</mk-6>\n'
Expand All @@ -266,7 +265,7 @@ def test_presentation(self):

try:
with SB(uc=True) as sb:
sb.driver.get("https://seleniumbase.io/simple/login")
sb.get("https://seleniumbase.io/simple/login")
sb.type("#username", "demo_user")
sb.type("#password", "secret_pass")
sb.click('a:contains("Sign in")')
Expand All @@ -285,7 +284,7 @@ def test_presentation(self):
code=(
"from seleniumbase import SB\n\n"
"with SB(uc=True<mk-1>, demo=True</mk-1>) as sb:\n"
' sb.driver.get('
' sb.get('
'"https://seleniumbase.io/simple/login")\n'
' sb.type("#username", "demo_user")\n'
' sb.type("#password", "secret_pass")\n'
Expand All @@ -301,7 +300,7 @@ def test_presentation(self):

try:
with SB(uc=True, demo=True) as sb:
sb.driver.get("https://seleniumbase.io/simple/login")
sb.get("https://seleniumbase.io/simple/login")
sb.type("#username", "demo_user")
sb.type("#password", "secret_pass")
sb.click('a:contains("Sign in")')
Expand Down Expand Up @@ -340,11 +339,11 @@ def test_presentation(self):
code=(
"from seleniumbase import SB\n\n"
"with SB(uc=True) as sb:\n"
' sb.driver.get("https://nowsecure.nl/#relax")\n'
' sb.get("https://nowsecure.nl/#relax")\n'
" sb.sleep(1)\n"
' if not sb.is_text_visible("OH YEAH, you passed", "h1"):\n'
" sb.get_new_driver(undetectable=True)\n"
' sb.driver.get("https://nowsecure.nl/#relax")\n'
' sb.get("https://nowsecure.nl/#relax")\n'
" sb.sleep(1)\n"
' sb.activate_demo_mode()\n'
' sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)\n'
Expand All @@ -354,10 +353,10 @@ def test_presentation(self):

try:
with SB(uc=True) as sb:
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.sleep(1)
if not sb.is_text_visible("OH YEAH, you passed", "h1"):
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.sleep(1)
sb.activate_demo_mode()
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)
Expand Down
30 changes: 15 additions & 15 deletions examples/presenter/uc_presentation_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_presentation_3(self):
self.begin_presentation(filename="uc_presentation.html")

self.open("https://seleniumbase.io/other/uc3_title.jpg")
self.sleep(3)
self.sleep(2.5)

self.create_presentation(theme="serif", transition="fade")
self.add_slide(
Expand Down Expand Up @@ -108,11 +108,11 @@ def test_presentation_3(self):
"<p><mk-0>Special <b>UC Mode</b> methods for clicking CAPTCHAs:"
"</mk-0></p><hr /><div></div>"
"<ul><br />\n"
"<li><mk-1><code><b>uc_gui_handle_captcha()</b></code></mk-1></li>"
"\n"
"<li><mk-1><code><b>sb.uc_gui_handle_captcha()</b></code></mk-1>"
"</li>\n"
"PyAutoGUI uses the TAB key with SPACEBAR.<br /><br />\n\n"
"<li><mk-2><code><b>uc_gui_click_captcha()</b></code></mk-2></li>"
"\n\n"
"<li><mk-2><code><b>sb.uc_gui_click_captcha()</b></code></mk-2>"
"</li>\n\n"
"PyAutoGUI clicks CAPTCHA with the mouse.<br />\n"
"(Note that you'll need to use this one on Linux!)\n"
"</ul>\n\n\n\n"
Expand Down Expand Up @@ -171,7 +171,7 @@ def test_presentation_3(self):
"<mk-2>with SB(uc=True) as sb:</mk-2>\n"
'<mk-3> url = "https://gitlab.com/users/sign_in"</mk-3>\n'
"<mk-4> sb.uc_open_with_reconnect(url, 4)</mk-4>\n"
"<mk-5> uc_gui_handle_captcha()</mk-5>\n\n"
"<mk-5> sb.uc_gui_handle_captcha()</mk-5>\n\n"
"<mk-6> ...</mk-6>\n\n\n\n\n\n"
),
)
Expand All @@ -183,7 +183,7 @@ def test_presentation_3(self):
"with SB(uc=True) as sb:\n"
' url = "https://gitlab.com/users/sign_in"\n'
" sb.uc_open_with_reconnect(url, 4)\n"
" uc_gui_handle_captcha()\n\n"
" sb.uc_gui_handle_captcha()\n\n"
'<mk-1> sb.assert_text("Username", \'[for="user_login"]\','
' timeout=3)</mk-1>\n'
'<mk-2> sb.assert_element(\'[for="user_login"]\')</mk-2>\n'
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_presentation_3(self):
"<mk-2>with SB(uc=True) as sb:</mk-2>\n"
'<mk-3> url = "https://gitlab.com/users/sign_in"</mk-3>\n'
"<mk-4> sb.uc_open_with_reconnect(url, 4)</mk-4>\n"
"<mk-5> uc_gui_click_captcha()</mk-5>\n\n"
"<mk-5> sb.uc_gui_click_captcha()</mk-5>\n\n"
"<mk-6> ...</mk-6>\n\n\n\n\n"
),
)
Expand All @@ -233,7 +233,7 @@ def test_presentation_3(self):
"with SB(uc=True) as sb:\n"
' url = "https://gitlab.com/users/sign_in"\n'
" sb.uc_open_with_reconnect(url, 4)\n"
" uc_gui_click_captcha()\n\n"
" sb.uc_gui_click_captcha()\n\n"
'<mk-1> sb.assert_text("Username", \'[for="user_login"]\','
' timeout=3)</mk-1>\n'
'<mk-2> sb.assert_element(\'[for="user_login"]\')</mk-2>\n'
Expand All @@ -252,8 +252,8 @@ def test_presentation_3(self):
"<li><mk-2>Navigate with stealth by calling "
"<code><b>sb.uc_open_with_reconnect(url)</b></code>"
"</mk-2></li><br />\n"
"<li><mk-3>Use <code><b>uc_gui_handle_captcha()</b></code>"
" or <code><b>uc_gui_click_captcha()</b></code>"
"<li><mk-3>Use <code><b>sb.uc_gui_handle_captcha()</b></code>"
" or <code><b>sb.uc_gui_click_captcha()</b></code>"
" to bypass CAPTCHAs as needed.</mk-3></li>\n"
"</ul>\n"
"<p><br /><mk-4>(It's that easy!)</mk-4></p><br />\n"
Expand All @@ -263,7 +263,7 @@ def test_presentation_3(self):
"<hr /><div></div><br />"
"<ul>\n"
"<li><mk-1>Previous tutorials mentioned this method:<br />"
"<code><b>uc_click(selector)</b></code>"
"<code><b>sb.uc_click(selector)</b></code>"
"</mk-1></li><br />\n"
"<mk-2>Although this method can no longer click a<br />"
"CAPTCHA directly, it should be used when<br />"
Expand All @@ -281,7 +281,7 @@ def test_presentation_3(self):
url = "https://ahrefs.com/website-authority-checker"
input_field = 'input[placeholder="Enter domain"]'
submit_button = 'span:contains("Check Authority")'
sb.uc_open_with_reconnect(url, 2) # The bot-check is later
sb.uc_open_with_reconnect(url) # The bot-check is later
sb.type(input_field, "github.com/seleniumbase/SeleniumBase")
sb.reconnect(0.1)
sb.uc_click(submit_button, reconnect_time=4)
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_presentation_3(self):
' url = "https://steamdb.info/"\n'
" sb.uc_open_with_reconnect(url, 3)\n"
' sb.uc_click("a.header-login span", 3)\n\n'
"<mk-0> uc_gui_click_captcha()</mk-0>\n"
"<mk-0> sb.uc_gui_click_captcha()</mk-0>\n"
'<mk-1> sb.assert_text("Sign in", "button#js-sign-in",'
' timeout=3)</mk-1>\n'
'<mk-2> sb.uc_click("button#js-sign-in", 2)</mk-2>\n'
Expand Down Expand Up @@ -726,7 +726,7 @@ def test_presentation_3(self):
"<p>👤 <mk-0>The plan to handle real-time bot-scanning</mk-0> 👤</p>"
"<hr /><h6><br /></h6>"
"<p>"
'<pre><code>uc_gui_click_captcha(frame="iframe", retry=False,'
'<pre><code>sb.uc_gui_click_captcha(frame="iframe", retry=False,'
' <mk-1>blind=True</mk-1>)</code></pre><br /><mk-1>'
'Set the third arg, `blind`, to `True` to force a retry'
' (if the first click failed) by clicking at the last known'
Expand Down
4 changes: 2 additions & 2 deletions examples/raw_ahrefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
url = "https://ahrefs.com/website-authority-checker"
input_field = 'input[placeholder="Enter domain"]'
submit_button = 'span:contains("Check Authority")'
sb.uc_open_with_reconnect(url, 2) # The bot-check is later
sb.uc_open_with_reconnect(url) # The bot-check is later
sb.type(input_field, "github.com/seleniumbase/SeleniumBase")
sb.reconnect(0.1)
sb.uc_click(submit_button, reconnect_time=4)
sb.uc_gui_click_captcha()
sb.wait_for_text_not_visible("Checking", timeout=10)
sb.wait_for_text_not_visible("Checking", timeout=12)
sb.highlight('p:contains("github.com/seleniumbase/SeleniumBase")')
sb.highlight('a:contains("Top 100 backlinks")')
sb.set_messenger_theme(location="bottom_center")
Expand Down
8 changes: 4 additions & 4 deletions examples/raw_cf.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""SB Manager using UC Mode & PyAutoGUI for bypassing CAPTCHAs."""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
with SB(uc=True, test=True, locale_code="en") as sb:
url = "https://www.cloudflare.com/login"
sb.uc_open_with_reconnect(url, 5)
sb.uc_open_with_reconnect(url, 5.5)
sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar
sb.sleep(2.5)

with SB(uc=True, test=True) as sb:
with SB(uc=True, test=True, locale_code="en") as sb:
url = "https://www.cloudflare.com/login"
sb.uc_open_with_reconnect(url, 5)
sb.uc_open_with_reconnect(url, 5.5)
sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it)
sb.sleep(2.5)
3 changes: 2 additions & 1 deletion examples/raw_order_tickets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from seleniumbase import SB

with SB(uc=True, test=True, ad_block=True) as sb:
url = "https://www.thaiticketmajor.com/concert/"
url = "https://www.thaiticketmajor.com/concert/#"
sb.uc_open_with_reconnect(url, 6.111)
sb.uc_click("button.btn-signin", 4.1)
sb.uc_gui_click_captcha()
sb.sleep(2)
12 changes: 7 additions & 5 deletions examples/raw_pixelscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
with SB(uc=True, incognito=True, test=True) as sb:
sb.driver.uc_open_with_reconnect("https://pixelscan.net/", 10)
sb.remove_elements("jdiv") # Remove chat widgets
sb.assert_text("No automation framework detected", "pxlscn-bot-detection")
not_masking = "You are not masking your fingerprint"
sb.assert_text(not_masking, "pxlscn-fingerprint-masking")
no_automation_detected = "No automation framework detected"
sb.assert_text(no_automation_detected, "pxlscn-bot-detection")
not_masking_text = "You are not masking your fingerprint"
sb.assert_text(not_masking_text, "pxlscn-fingerprint-masking")
sb.highlight("span.text-success", loops=8)
sb.sleep(1)
sb.highlight("pxlscn-fingerprint-masking div", loops=9, scroll=False)
fingerprint_masking_div = "pxlscn-fingerprint-masking div"
sb.highlight(fingerprint_masking_div, loops=9, scroll=False)
sb.sleep(1)
sb.highlight("div.bot-detection-context", loops=10, scroll=False)
sb.highlight(".bot-detection-context", loops=10, scroll=False)
sb.sleep(2)
31 changes: 18 additions & 13 deletions help_docs/thank_you.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
<!-- SeleniumBase Docs -->

[<img src="https://seleniumbase.github.io/cdn/img/super_logo_sb.png" title="SeleniumBase" width="290">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
<a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/super_logo_sb.png" title="SeleniumBase" width="290" /></a>

### Thank you for flying with SeleniumBase! 🦅

<h3>🛬🛫 Thank you for flying with SeleniumBase! 🦅🚀</h3>

--------

<p><div><b>SeleniumBase Playlist on YouTube:</b></div></p>
<p><div><b>🛩️ SeleniumBase Playlist on YouTube:</b></div></p>

<p><span><a href="https://www.youtube.com/playlist?list=PLp9uKicxkBc5UIlGi2BuE3aWC7JyXpD3m"><img src="https://seleniumbase.github.io/cdn/img/youtube.png" title="SeleniumBase Playlist on YouTube" alt="SeleniumBase Playlist on YouTube" width="76" /></a></span></p>

<p><span><a href="https://www.youtube.com/playlist?list=PLp9uKicxkBc5UIlGi2BuE3aWC7JyXpD3m"><img src="https://seleniumbase.github.io/cdn/img/youtube.png" title="SeleniumBase Playlist on YouTube" alt="SeleniumBase Playlist on YouTube" width="64" /></a></span></p>
<p><div><b>🛩️ SeleniumBase GitHub Home Page:</b></div></p>

<p><div><b>SeleniumBase GitHub Repo Link:</b></div></p>
<p><div><span><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://seleniumbase.github.io/img/social/share_github.svg" title="SeleniumBase on GitHub" alt="SeleniumBase on GitHub" width="74" /></a></span></div></p>

<p><div><span><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://seleniumbase.github.io/img/social/share_github.svg" title="SeleniumBase on GitHub" alt="SeleniumBase on GitHub" width="54" /></a></span></div></p>
<p><div><b>🛩️ SeleniumBase Discord Channel:</b></div></p>

<p><div><b>SeleniumBase Gitter Chat Link:</b></div></p>
<p><span><a href="https://discord.gg/EdhQTn3EyE"><img src="https://seleniumbase.github.io/other/discord_icon.png" title="SeleniumBase on Discord" alt="SeleniumBase on Discord" width="72" /></a></span></p>

<p><span><a href="https://gitter.im/seleniumbase/SeleniumBase"><img src="https://seleniumbase.github.io/img/social/share_gitter.svg" title="SeleniumBase on Gitter" alt="SeleniumBase on Gitter" width="42" /></a></span></p>
<p><div><b>🛩️ SeleniumBase Gitter Chat:</b></div></p>

<p><span><a href="https://gitter.im/seleniumbase/SeleniumBase"><img src="https://seleniumbase.github.io/img/social/share_gitter.svg" title="SeleniumBase on Gitter" alt="SeleniumBase on Gitter" width="56" /></a></span></p>

<p><div><b>Other Social Media Links:</b></div></p>

</div></p>
<span><a href="https://www.facebook.com/SeleniumBase"><img src="https://seleniumbase.github.io/img/social/share_facebook.svg" title="SeleniumBase on Facebook" alt="SeleniumBase on Facebook" width="46" /></a></span>
<span><a href="https://twitter.com/seleniumbase"><img src="https://seleniumbase.github.io/img/social/share_twitter.svg" title="SeleniumBase on Twitter" alt="SeleniumBase on Twitter" width="46" /></a></span>
<span><a href="https://instagram.com/seleniumbase"><img src="https://seleniumbase.github.io/img/social/share_instagram.svg" title="SeleniumBase on Instagram" alt="SeleniumBase on Instagram" width="40" /></a></span>
<div></p>
<span><a href="https://www.facebook.com/SeleniumBase"><img src="https://seleniumbase.github.io/img/social/share_facebook.svg" title="SeleniumBase on Facebook" alt="SeleniumBase on Facebook" width="50" /></a></span>
<span><a href="https://twitter.com/seleniumbase"><img src="https://seleniumbase.github.io/img/social/share_twitter.svg" title="SeleniumBase on Twitter" alt="SeleniumBase on Twitter" width="50" /></a></span>
<span><a href="https://instagram.com/seleniumbase"><img src="https://seleniumbase.github.io/img/social/share_instagram.svg" title="SeleniumBase on Instagram" alt="SeleniumBase on Instagram" width="42" /></a></span>
</div></p>

--------

<p><div><a align="center" href="https://github.com/seleniumbase/SeleniumBase/"><img align="center" src="https://seleniumbase.github.io/img/sb_logo_10.png" alt="SeleniumBase" width="260"></a></div></p>
<p><div><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/img/sb_logo_10.png" alt="SeleniumBase" width="260"></a></div></p>
Loading

0 comments on commit 4c745d2

Please sign in to comment.