Update examples

This commit is contained in:
Michael Mintz 2024-09-04 22:59:03 -04:00
parent 111f8eefbd
commit fab150b881
6 changed files with 40 additions and 38 deletions

View File

@ -30,12 +30,12 @@ class UCPresentationClass(BaseCase):
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:
@ -249,8 +249,7 @@ class UCPresentationClass(BaseCase):
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'
@ -266,7 +265,7 @@ class UCPresentationClass(BaseCase):
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")')
@ -285,7 +284,7 @@ class UCPresentationClass(BaseCase):
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'
@ -301,7 +300,7 @@ class UCPresentationClass(BaseCase):
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")')
@ -340,11 +339,11 @@ class UCPresentationClass(BaseCase):
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'
@ -354,10 +353,10 @@ class UCPresentationClass(BaseCase):
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)

View File

@ -18,7 +18,7 @@ class UCPresentationClass(BaseCase):
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(
@ -108,11 +108,11 @@ class UCPresentationClass(BaseCase):
"<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"
@ -171,7 +171,7 @@ class UCPresentationClass(BaseCase):
"<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"
),
)
@ -183,7 +183,7 @@ class UCPresentationClass(BaseCase):
"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'
@ -221,7 +221,7 @@ class UCPresentationClass(BaseCase):
"<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"
),
)
@ -233,7 +233,7 @@ class UCPresentationClass(BaseCase):
"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'
@ -252,8 +252,8 @@ class UCPresentationClass(BaseCase):
"<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"
@ -263,7 +263,7 @@ class UCPresentationClass(BaseCase):
"<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 />"
@ -281,7 +281,7 @@ class UCPresentationClass(BaseCase):
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)
@ -349,7 +349,7 @@ class UCPresentationClass(BaseCase):
' 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'
@ -726,7 +726,7 @@ class UCPresentationClass(BaseCase):
"<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'

View File

@ -4,12 +4,12 @@ with SB(uc=True, test=True, incognito=True, locale_code="en") as sb:
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")

View File

@ -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)

View File

@ -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)

View File

@ -3,12 +3,14 @@ from seleniumbase import SB
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)