Skip to content

UC Mode refinements and more #2649

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 5 commits into from
Mar 31, 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
10 changes: 7 additions & 3 deletions examples/raw_bing_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

with SB(uc=True, test=True) as sb:
url = "https://www.bing.com/turing/captcha/challenge"
sb.driver.uc_open_with_tab(url)
sb.driver.uc_open_with_reconnect(url, 1.25)
sb.add_css_style("iframe{zoom: 2}") # Make it bigger
sb.switch_to_frame("iframe")
if not sb.is_element_visible("div#success"):
sb.driver.uc_open_with_reconnect(url, 4.05)
sb.add_css_style("iframe{zoom: 2}")
sb.switch_to_frame("iframe")
sb.highlight("div#success", loops=2)
sb.assert_text("Success!", "span#success-text")
sb.activate_demo_mode() # See asserts as they happen
sb.assert_element("svg#success-icon")
sb.assert_text("Success!", "span#success-text")
sb.highlight("div#success")
8 changes: 4 additions & 4 deletions examples/raw_nopecha.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
sb.driver.uc_open_with_reconnect("nopecha.com/demo/turnstile", 4.2)
sb.driver.uc_open_with_reconnect("nopecha.com/demo/turnstile", 4.5)
sb.switch_to_frame("#example-container5 iframe")
sb.driver.uc_click("span.mark")
sb.driver.uc_click("span.mark", reconnect_time=3)

if sb.is_element_visible("#example-container0 iframe"):
sb.switch_to_frame("#example-container0 iframe")
if not sb.is_element_visible("circle.success-circle"):
sb.driver.uc_click("span.mark")
sb.driver.uc_click("span.mark", reconnect_time=3)
sb.switch_to_frame("#example-container0 iframe")
sb.assert_element("circle.success-circle")
sb.switch_to_parent_frame()
Expand All @@ -17,4 +17,4 @@
sb.assert_element("svg#success-icon", timeout=3)
sb.switch_to_parent_frame()
sb.set_messenger_theme(location="top_center")
sb.post_message("Selenium wasn't detected!", duration=3)
sb.post_message("SeleniumBase wasn't detected!", duration=3)
8 changes: 4 additions & 4 deletions examples/raw_pixelscan.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from seleniumbase import SB

with SB(uc=True, incognito=True, test=True) as sb:
sb.driver.uc_open_with_reconnect("https://pixelscan.net/", 11)
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")
sb.assert_text("You are not masking your fingerprint")
sb.highlight("span.text-success", loops=10)
sb.highlight("span.text-success", loops=8)
sb.sleep(1)
sb.highlight("pxlscn-fingerprint-masking div", loops=10, scroll=False)
sb.highlight("pxlscn-fingerprint-masking div", loops=9, scroll=False)
sb.sleep(1)
sb.highlight("div.bot-detection-context", loops=10, scroll=False)
sb.sleep(3)
sb.sleep(2)
2 changes: 2 additions & 0 deletions examples/test_docs_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ def test_docs(self):
self.assert_text("Recorder Mode", "h1")
self.js_click('a[href$="/method_summary/"]')
self.assert_text("API Reference", "h1")
self.js_click('a[href$="/uc_mode/"]')
self.assert_text("UC Mode", "h1")
self.click('img[alt="logo"]')
self.assert_text("SeleniumBase", "h1")
157 changes: 127 additions & 30 deletions help_docs/uc_mode.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

regex>=2023.12.25
pymdown-extensions>=10.7.1
pipdeptree>=2.16.1
pipdeptree>=2.16.2
python-dateutil>=2.8.2
Markdown==3.6
markdown2==2.4.13
Expand All @@ -16,11 +16,11 @@ cairocffi==1.6.1
pathspec==0.12.1
Babel==2.14.0
paginate==0.5.6
lxml==5.1.0
lxml==5.1.1
pyquery==2.0.0
readtime==3.0.0
mkdocs==1.5.3
mkdocs-material==9.5.14
mkdocs-material==9.5.15
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1
13 changes: 6 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ wheel>=0.43.0;python_version>="3.8"
attrs>=23.2.0
certifi>=2024.2.2
filelock>=3.12.2;python_version<"3.8"
filelock>=3.13.1;python_version>="3.8"
filelock>=3.13.3;python_version>="3.8"
platformdirs>=4.0.0;python_version<"3.8"
platformdirs>=4.2.0;python_version>="3.8"
typing-extensions>=4.10.0;python_version>="3.8"
Expand All @@ -21,7 +21,7 @@ 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"
requests==2.31.0
pynose==1.5.0
pynose==1.5.1
sniffio==1.3.1
h11==0.14.0
outcome==1.3.0.post0
Expand All @@ -30,7 +30,7 @@ trio==0.25.0;python_version>="3.8"
trio-websocket==0.11.1
wsproto==1.2.0
selenium==4.11.2;python_version<"3.8"
selenium==4.18.1;python_version>="3.8"
selenium==4.19.0;python_version>="3.8"
cssselect==1.2.0
sortedcontainers==2.4.0
fasteners==0.19
Expand Down Expand Up @@ -69,11 +69,10 @@ rich==13.7.1
# --- Testing Requirements --- #
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)

coverage==6.2;python_version<"3.7"
coverage==7.2.7;python_version>="3.7" and python_version<"3.8"
coverage==7.2.7;python_version<"3.8"
coverage==7.4.4;python_version>="3.8"
pytest-cov==4.0.0;python_version<"3.7"
pytest-cov==4.1.0;python_version>="3.7"
pytest-cov==4.1.0;python_version<"3.8"
pytest-cov==5.0.0;python_version>="3.8"
flake8==5.0.4;python_version<"3.9"
flake8==7.0.0;python_version>="3.9"
mccabe==0.7.0
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.24.12"
__version__ = "4.25.0"
19 changes: 12 additions & 7 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from seleniumbase.core import proxy_helper
from seleniumbase.core import sb_driver
from seleniumbase.fixtures import constants
from seleniumbase.fixtures import js_utils
from seleniumbase.fixtures import shared_utils

urllib3.disable_warnings()
Expand Down Expand Up @@ -406,9 +407,9 @@ def uc_open(driver, url):
elif ":" not in url:
url = "https://" + url
if (url.startswith("http:") or url.startswith("https:")):
time.sleep(0.05)
with driver:
driver.default_get(url)
script = 'window.location.href = "%s";' % url
js_utils.call_me_later(driver, script, 33)
else:
driver.default_get(url) # The original one
return None
Expand All @@ -420,7 +421,6 @@ def uc_open_with_tab(driver, url):
elif ":" not in url:
url = "https://" + url
if (url.startswith("http:") or url.startswith("https:")):
time.sleep(0.05)
with driver:
driver.execute_script('window.open("%s","_blank");' % url)
driver.close()
Expand All @@ -439,7 +439,9 @@ def uc_open_with_reconnect(driver, url, reconnect_time=None):
elif ":" not in url:
url = "https://" + url
if (url.startswith("http:") or url.startswith("https:")):
driver.execute_script('window.open("%s","_blank");' % url)
script = 'window.open("%s","_blank");' % url
js_utils.call_me_later(driver, script, 3)
time.sleep(0.007)
driver.close()
driver.reconnect(reconnect_time)
driver.switch_to.window(driver.window_handles[-1])
Expand Down Expand Up @@ -3878,7 +3880,7 @@ def get_local_driver(
service=service, options=chrome_options
)
return extend_driver(driver)
except Exception:
except Exception as original_exception:
if is_using_uc(undetectable, browser_name):
raise
# Try again if Chrome didn't launch
Expand Down Expand Up @@ -3914,8 +3916,11 @@ def get_local_driver(
log_output=os.devnull,
service_args=["--disable-build-check"]
)
driver = webdriver.Chrome(service=service)
return extend_driver(driver)
try:
driver = webdriver.Chrome(service=service)
return extend_driver(driver)
except Exception:
raise original_exception
else:
raise Exception(
"%s is not a valid browser option for this system!" % browser_name
Expand Down
5 changes: 4 additions & 1 deletion seleniumbase/undetected/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ def uc_click(
tag_name=None,
):
if driver and selector and by:
if tag_name == "span" and ":contains" not in selector:
delayed_click = False
if tag_name == "span" or tag_name == "button" or tag_name == "div":
delayed_click = True
if delayed_click and ":contains" not in selector:
selector = js_utils.convert_to_css_selector(selector, by)
script = 'document.querySelector("%s").click();' % selector
js_utils.call_me_later(driver, script, 111)
Expand Down
24 changes: 15 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
'attrs>=23.2.0',
"certifi>=2024.2.2",
'filelock>=3.12.2;python_version<"3.8"',
'filelock>=3.13.1;python_version>="3.8"',
'filelock>=3.13.3;python_version>="3.8"',
'platformdirs>=4.0.0;python_version<"3.8"',
'platformdirs>=4.2.0;python_version>="3.8"',
'typing-extensions>=4.10.0;python_version>="3.8"',
Expand All @@ -169,7 +169,7 @@
'urllib3>=1.26.18,<2;python_version<"3.10"',
'urllib3>=1.26.18,<2.3.0;python_version>="3.10"',
'requests==2.31.0',
"pynose==1.5.0",
"pynose==1.5.1",
'sniffio==1.3.1',
'h11==0.14.0',
'outcome==1.3.0.post0',
Expand All @@ -178,7 +178,7 @@
'trio-websocket==0.11.1',
'wsproto==1.2.0',
'selenium==4.11.2;python_version<"3.8"',
'selenium==4.18.1;python_version>="3.8"',
'selenium==4.19.0;python_version>="3.8"',
'cssselect==1.2.0',
"sortedcontainers==2.4.0",
'fasteners==0.19',
Expand Down Expand Up @@ -219,16 +219,17 @@
# Usage: pytest --alluredir=allure_results
# Serve: allure serve allure_results
"allure": [
'allure-pytest==2.13.3',
'allure-python-commons==2.13.3',
'allure-behave==2.13.3',
'allure-pytest==2.13.4',
'allure-python-commons==2.13.4',
'allure-behave==2.13.4',
],
# pip install -e .[coverage]
# Usage: coverage run -m pytest; coverage html; coverage report
"coverage": [
'coverage==7.2.7;python_version<"3.8"',
'coverage==7.4.4;python_version>="3.8"',
'pytest-cov==4.1.0',
'pytest-cov==4.1.0;python_version<"3.8"',
'pytest-cov==5.0.0;python_version>="3.8"',
],
# pip install -e .[flake8]
# Usage: flake8
Expand Down Expand Up @@ -256,15 +257,20 @@
'cryptography==42.0.5;python_version>="3.9"',
'cffi==1.15.1;python_version<"3.8"',
'cffi==1.16.0;python_version>="3.8"',
"pycparser==2.21",

"pycparser==2.22",
],
# pip install -e .[pillow]
# (An optional library for image-processing.)
"pillow": [
'Pillow==9.5.0;python_version<"3.8"',
'Pillow==10.2.0;python_version>="3.8"',
],
# pip install -e .[pip-system-certs]
# (If you see [SSL: CERTIFICATE_VERIFY_FAILED], then get this.)
# (May help those with corporate self-signed certs on Windows.)
"pip-system-certs": [
'pip-system-certs==4.0;platform_system=="Windows"',
],
# pip install -e .[proxy]
# Usage: proxy
# (That starts a proxy server on "127.0.0.1:8899".)
Expand Down