Skip to content

Commit ef2fed2

Browse files
authored
Merge pull request #2649 from seleniumbase/uc-mode-refinements
UC Mode refinements and more
2 parents a5992f2 + f026030 commit ef2fed2

File tree

11 files changed

+185
-69
lines changed

11 files changed

+185
-69
lines changed

examples/raw_bing_captcha.py

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

44
with SB(uc=True, test=True) as sb:
55
url = "https://www.bing.com/turing/captcha/challenge"
6-
sb.driver.uc_open_with_tab(url)
6+
sb.driver.uc_open_with_reconnect(url, 1.25)
77
sb.add_css_style("iframe{zoom: 2}") # Make it bigger
88
sb.switch_to_frame("iframe")
9+
if not sb.is_element_visible("div#success"):
10+
sb.driver.uc_open_with_reconnect(url, 4.05)
11+
sb.add_css_style("iframe{zoom: 2}")
12+
sb.switch_to_frame("iframe")
13+
sb.highlight("div#success", loops=2)
14+
sb.assert_text("Success!", "span#success-text")
915
sb.activate_demo_mode() # See asserts as they happen
1016
sb.assert_element("svg#success-icon")
11-
sb.assert_text("Success!", "span#success-text")
12-
sb.highlight("div#success")

examples/raw_nopecha.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from seleniumbase import SB
22

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

88
if sb.is_element_visible("#example-container0 iframe"):
99
sb.switch_to_frame("#example-container0 iframe")
1010
if not sb.is_element_visible("circle.success-circle"):
11-
sb.driver.uc_click("span.mark")
11+
sb.driver.uc_click("span.mark", reconnect_time=3)
1212
sb.switch_to_frame("#example-container0 iframe")
1313
sb.assert_element("circle.success-circle")
1414
sb.switch_to_parent_frame()
@@ -17,4 +17,4 @@
1717
sb.assert_element("svg#success-icon", timeout=3)
1818
sb.switch_to_parent_frame()
1919
sb.set_messenger_theme(location="top_center")
20-
sb.post_message("Selenium wasn't detected!", duration=3)
20+
sb.post_message("SeleniumBase wasn't detected!", duration=3)

examples/raw_pixelscan.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from seleniumbase import SB
22

33
with SB(uc=True, incognito=True, test=True) as sb:
4-
sb.driver.uc_open_with_reconnect("https://pixelscan.net/", 11)
4+
sb.driver.uc_open_with_reconnect("https://pixelscan.net/", 10)
55
sb.remove_elements("jdiv") # Remove chat widgets
66
sb.assert_text("No automation framework detected", "pxlscn-bot-detection")
77
sb.assert_text("You are not masking your fingerprint")
8-
sb.highlight("span.text-success", loops=10)
8+
sb.highlight("span.text-success", loops=8)
99
sb.sleep(1)
10-
sb.highlight("pxlscn-fingerprint-masking div", loops=10, scroll=False)
10+
sb.highlight("pxlscn-fingerprint-masking div", loops=9, scroll=False)
1111
sb.sleep(1)
1212
sb.highlight("div.bot-detection-context", loops=10, scroll=False)
13-
sb.sleep(3)
13+
sb.sleep(2)

examples/test_docs_site.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ def test_docs(self):
1616
self.assert_text("Recorder Mode", "h1")
1717
self.js_click('a[href$="/method_summary/"]')
1818
self.assert_text("API Reference", "h1")
19+
self.js_click('a[href$="/uc_mode/"]')
20+
self.assert_text("UC Mode", "h1")
1921
self.click('img[alt="logo"]')
2022
self.assert_text("SeleniumBase", "h1")

help_docs/uc_mode.md

Lines changed: 127 additions & 30 deletions
Large diffs are not rendered by default.

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>=2023.12.25
55
pymdown-extensions>=10.7.1
6-
pipdeptree>=2.16.1
6+
pipdeptree>=2.16.2
77
python-dateutil>=2.8.2
88
Markdown==3.6
99
markdown2==2.4.13
@@ -16,11 +16,11 @@ cairocffi==1.6.1
1616
pathspec==0.12.1
1717
Babel==2.14.0
1818
paginate==0.5.6
19-
lxml==5.1.0
19+
lxml==5.1.1
2020
pyquery==2.0.0
2121
readtime==3.0.0
2222
mkdocs==1.5.3
23-
mkdocs-material==9.5.14
23+
mkdocs-material==9.5.15
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: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ wheel>=0.43.0;python_version>="3.8"
77
attrs>=23.2.0
88
certifi>=2024.2.2
99
filelock>=3.12.2;python_version<"3.8"
10-
filelock>=3.13.1;python_version>="3.8"
10+
filelock>=3.13.3;python_version>="3.8"
1111
platformdirs>=4.0.0;python_version<"3.8"
1212
platformdirs>=4.2.0;python_version>="3.8"
1313
typing-extensions>=4.10.0;python_version>="3.8"
@@ -21,7 +21,7 @@ charset-normalizer==3.3.2
2121
urllib3>=1.26.18,<2;python_version<"3.10"
2222
urllib3>=1.26.18,<2.3.0;python_version>="3.10"
2323
requests==2.31.0
24-
pynose==1.5.0
24+
pynose==1.5.1
2525
sniffio==1.3.1
2626
h11==0.14.0
2727
outcome==1.3.0.post0
@@ -30,7 +30,7 @@ trio==0.25.0;python_version>="3.8"
3030
trio-websocket==0.11.1
3131
wsproto==1.2.0
3232
selenium==4.11.2;python_version<"3.8"
33-
selenium==4.18.1;python_version>="3.8"
33+
selenium==4.19.0;python_version>="3.8"
3434
cssselect==1.2.0
3535
sortedcontainers==2.4.0
3636
fasteners==0.19
@@ -69,11 +69,10 @@ rich==13.7.1
6969
# --- Testing Requirements --- #
7070
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)
7171

72-
coverage==6.2;python_version<"3.7"
73-
coverage==7.2.7;python_version>="3.7" and python_version<"3.8"
72+
coverage==7.2.7;python_version<"3.8"
7473
coverage==7.4.4;python_version>="3.8"
75-
pytest-cov==4.0.0;python_version<"3.7"
76-
pytest-cov==4.1.0;python_version>="3.7"
74+
pytest-cov==4.1.0;python_version<"3.8"
75+
pytest-cov==5.0.0;python_version>="3.8"
7776
flake8==5.0.4;python_version<"3.9"
7877
flake8==7.0.0;python_version>="3.9"
7978
mccabe==0.7.0

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.24.12"
2+
__version__ = "4.25.0"

seleniumbase/core/browser_launcher.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from seleniumbase.core import proxy_helper
2828
from seleniumbase.core import sb_driver
2929
from seleniumbase.fixtures import constants
30+
from seleniumbase.fixtures import js_utils
3031
from seleniumbase.fixtures import shared_utils
3132

3233
urllib3.disable_warnings()
@@ -406,9 +407,9 @@ def uc_open(driver, url):
406407
elif ":" not in url:
407408
url = "https://" + url
408409
if (url.startswith("http:") or url.startswith("https:")):
409-
time.sleep(0.05)
410410
with driver:
411-
driver.default_get(url)
411+
script = 'window.location.href = "%s";' % url
412+
js_utils.call_me_later(driver, script, 33)
412413
else:
413414
driver.default_get(url) # The original one
414415
return None
@@ -420,7 +421,6 @@ def uc_open_with_tab(driver, url):
420421
elif ":" not in url:
421422
url = "https://" + url
422423
if (url.startswith("http:") or url.startswith("https:")):
423-
time.sleep(0.05)
424424
with driver:
425425
driver.execute_script('window.open("%s","_blank");' % url)
426426
driver.close()
@@ -439,7 +439,9 @@ def uc_open_with_reconnect(driver, url, reconnect_time=None):
439439
elif ":" not in url:
440440
url = "https://" + url
441441
if (url.startswith("http:") or url.startswith("https:")):
442-
driver.execute_script('window.open("%s","_blank");' % url)
442+
script = 'window.open("%s","_blank");' % url
443+
js_utils.call_me_later(driver, script, 3)
444+
time.sleep(0.007)
443445
driver.close()
444446
driver.reconnect(reconnect_time)
445447
driver.switch_to.window(driver.window_handles[-1])
@@ -3878,7 +3880,7 @@ def get_local_driver(
38783880
service=service, options=chrome_options
38793881
)
38803882
return extend_driver(driver)
3881-
except Exception:
3883+
except Exception as original_exception:
38823884
if is_using_uc(undetectable, browser_name):
38833885
raise
38843886
# Try again if Chrome didn't launch
@@ -3914,8 +3916,11 @@ def get_local_driver(
39143916
log_output=os.devnull,
39153917
service_args=["--disable-build-check"]
39163918
)
3917-
driver = webdriver.Chrome(service=service)
3918-
return extend_driver(driver)
3919+
try:
3920+
driver = webdriver.Chrome(service=service)
3921+
return extend_driver(driver)
3922+
except Exception:
3923+
raise original_exception
39193924
else:
39203925
raise Exception(
39213926
"%s is not a valid browser option for this system!" % browser_name

seleniumbase/undetected/webelement.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ def uc_click(
1212
tag_name=None,
1313
):
1414
if driver and selector and by:
15-
if tag_name == "span" and ":contains" not in selector:
15+
delayed_click = False
16+
if tag_name == "span" or tag_name == "button" or tag_name == "div":
17+
delayed_click = True
18+
if delayed_click and ":contains" not in selector:
1619
selector = js_utils.convert_to_css_selector(selector, by)
1720
script = 'document.querySelector("%s").click();' % selector
1821
js_utils.call_me_later(driver, script, 111)

setup.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
'attrs>=23.2.0',
156156
"certifi>=2024.2.2",
157157
'filelock>=3.12.2;python_version<"3.8"',
158-
'filelock>=3.13.1;python_version>="3.8"',
158+
'filelock>=3.13.3;python_version>="3.8"',
159159
'platformdirs>=4.0.0;python_version<"3.8"',
160160
'platformdirs>=4.2.0;python_version>="3.8"',
161161
'typing-extensions>=4.10.0;python_version>="3.8"',
@@ -169,7 +169,7 @@
169169
'urllib3>=1.26.18,<2;python_version<"3.10"',
170170
'urllib3>=1.26.18,<2.3.0;python_version>="3.10"',
171171
'requests==2.31.0',
172-
"pynose==1.5.0",
172+
"pynose==1.5.1",
173173
'sniffio==1.3.1',
174174
'h11==0.14.0',
175175
'outcome==1.3.0.post0',
@@ -178,7 +178,7 @@
178178
'trio-websocket==0.11.1',
179179
'wsproto==1.2.0',
180180
'selenium==4.11.2;python_version<"3.8"',
181-
'selenium==4.18.1;python_version>="3.8"',
181+
'selenium==4.19.0;python_version>="3.8"',
182182
'cssselect==1.2.0',
183183
"sortedcontainers==2.4.0",
184184
'fasteners==0.19',
@@ -219,16 +219,17 @@
219219
# Usage: pytest --alluredir=allure_results
220220
# Serve: allure serve allure_results
221221
"allure": [
222-
'allure-pytest==2.13.3',
223-
'allure-python-commons==2.13.3',
224-
'allure-behave==2.13.3',
222+
'allure-pytest==2.13.4',
223+
'allure-python-commons==2.13.4',
224+
'allure-behave==2.13.4',
225225
],
226226
# pip install -e .[coverage]
227227
# Usage: coverage run -m pytest; coverage html; coverage report
228228
"coverage": [
229229
'coverage==7.2.7;python_version<"3.8"',
230230
'coverage==7.4.4;python_version>="3.8"',
231-
'pytest-cov==4.1.0',
231+
'pytest-cov==4.1.0;python_version<"3.8"',
232+
'pytest-cov==5.0.0;python_version>="3.8"',
232233
],
233234
# pip install -e .[flake8]
234235
# Usage: flake8
@@ -256,15 +257,20 @@
256257
'cryptography==42.0.5;python_version>="3.9"',
257258
'cffi==1.15.1;python_version<"3.8"',
258259
'cffi==1.16.0;python_version>="3.8"',
259-
"pycparser==2.21",
260-
260+
"pycparser==2.22",
261261
],
262262
# pip install -e .[pillow]
263263
# (An optional library for image-processing.)
264264
"pillow": [
265265
'Pillow==9.5.0;python_version<"3.8"',
266266
'Pillow==10.2.0;python_version>="3.8"',
267267
],
268+
# pip install -e .[pip-system-certs]
269+
# (If you see [SSL: CERTIFICATE_VERIFY_FAILED], then get this.)
270+
# (May help those with corporate self-signed certs on Windows.)
271+
"pip-system-certs": [
272+
'pip-system-certs==4.0;platform_system=="Windows"',
273+
],
268274
# pip install -e .[proxy]
269275
# Usage: proxy
270276
# (That starts a proxy server on "127.0.0.1:8899".)

0 commit comments

Comments
 (0)