Skip to content

Commit 61e0d89

Browse files
authored
Merge pull request #1411 from seleniumbase/reliability-updates-for-firefox-and-js-click
Reliability updates for Firefox and js_click()
2 parents efb607d + 38582b1 commit 61e0d89

File tree

6 files changed

+52
-17
lines changed

6 files changed

+52
-17
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta property="og:image" content="https://seleniumbase.io/cdn/img/mac_sb_logo_5.png" />
66
<link rel="icon" href="https://seleniumbase.io/img/green_logo2.png" />
77

8-
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/sb_media_logo_5.png" alt="SeleniumBase" title="SeleniumBase" width="300" /></a></p>
8+
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/mac_sb_logo_5b.png" alt="SeleniumBase" title="SeleniumBase" width="320" /></a></p>
99
<p align="center"><b>Powerful end-to-end testing with <a href="https://www.selenium.dev/documentation/">Selenium</a>, <a href="https://www.python.org/about/">Python</a>, and <a href="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a>.</b></p>
1010

1111
<p align="center"><a href="https://pypi.python.org/pypi/seleniumbase" target="_blank"><img src="https://img.shields.io/pypi/v/seleniumbase.svg?color=3399EE" alt="PyPI version" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/releases" target="_blank"><img src="https://img.shields.io/github/v/release/seleniumbase/SeleniumBase.svg?color=22AAEE" alt="GitHub version" /></a> <a href="https://seleniumbase.io"><img src="https://img.shields.io/badge/docs-seleniumbase.io-11BBAA.svg" alt="SeleniumBase Docs" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/actions" target="_blank"><img src="https://github.com/seleniumbase/SeleniumBase/workflows/CI%20build/badge.svg" alt="SeleniumBase GitHub Actions" /></a> <a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" alt="SeleniumBase" /></a></p>
@@ -16,7 +16,7 @@
1616
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">✅ Examples</a> |
1717
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md">🎛️ Options</a> |
1818
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/console_scripts/ReadMe.md">🔮 Scripts</a> |
19-
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/mobile_testing.md">📱 Mobile</a>
19+
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/mobile_testing.md">📱 Phone</a>
2020
<br />
2121
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md">📙 APIs</a> |
2222
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">📝 Formats</a> |
@@ -43,9 +43,7 @@
4343

4444
--------
4545

46-
<a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/sb_text_f.png" alt="SeleniumBase" title="SeleniumBase" width="260" /></a>
47-
48-
<p align="left">✅ An example of running a test with <b>pytest</b>: <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_demo_site.py">test_demo_site.py</a></p>
46+
<p align="left"><img src="https://seleniumbase.io/img/green_logo2.png" title="SeleniumBase" width="22" /> An example of running a test with <b>pytest</b>: <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_demo_site.py">test_demo_site.py</a></p>
4947

5048
```bash
5149
cd examples/

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ packaging>=20.9;python_version<"3.6"
55
packaging>=21.3;python_version>="3.6"
66
setuptools>=44.1.1;python_version<"3.6"
77
setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"
8-
setuptools>=63.1.0;python_version>="3.7"
8+
setuptools>=63.2.0;python_version>="3.7"
99
tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"
1010
tomli>=2.0.1;python_version>="3.7"
1111
wheel>=0.37.1

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__ = "3.5.2"
2+
__version__ = "3.5.3"

seleniumbase/core/browser_launcher.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,8 @@ def _set_firefox_options(
538538
options.set_preference("pdfjs.disabled", True)
539539
options.set_preference("app.update.auto", False)
540540
options.set_preference("app.update.enabled", False)
541-
options.set_preference("app.update.silent", True)
542541
options.set_preference("browser.formfill.enable", False)
543-
options.set_preference("browser.privatebrowsing.autostart", False)
544-
options.set_preference("devtools.errorconsole.enabled", True)
542+
options.set_preference("browser.privatebrowsing.autostart", True)
545543
options.set_preference("dom.webnotifications.enabled", False)
546544
options.set_preference("dom.disable_beforeunload", True)
547545
options.set_preference("browser.contentblocking.database.enabled", True)
@@ -550,7 +548,6 @@ def _set_firefox_options(
550548
options.set_preference("extensions.systemAddon.update.enabled", False)
551549
options.set_preference("extensions.update.autoUpdateDefault", False)
552550
options.set_preference("extensions.update.enabled", False)
553-
options.set_preference("extensions.update.silent", True)
554551
options.set_preference("datareporting.healthreport.service.enabled", False)
555552
options.set_preference("datareporting.healthreport.uploadEnabled", False)
556553
options.set_preference("datareporting.policy.dataSubmissionEnabled", False)
@@ -1514,7 +1511,11 @@ def get_local_driver(
15141511
options=firefox_options,
15151512
)
15161513
except Exception as e:
1517-
if "Process unexpectedly closed" in e.msg:
1514+
if (
1515+
"Process unexpectedly closed" in e.msg
1516+
or "Failed to read marionette port" in e.msg
1517+
or "A connection attempt failed" in e.msg
1518+
):
15181519
# Firefox probably just auto-updated itself.
15191520
# Trying again right after that often works.
15201521
return webdriver.Firefox(
@@ -1532,9 +1533,24 @@ def get_local_driver(
15321533
else:
15331534
if selenium4:
15341535
service = FirefoxService(log_path=os.path.devnull)
1535-
return webdriver.Firefox(
1536-
service=service, options=firefox_options
1537-
)
1536+
try:
1537+
return webdriver.Firefox(
1538+
service=service, options=firefox_options
1539+
)
1540+
except Exception as e:
1541+
if (
1542+
"Process unexpectedly closed" in e.msg
1543+
or "Failed to read marionette port" in e.msg
1544+
or "A connection attempt failed" in e.msg
1545+
):
1546+
# Firefox probably just auto-updated itself.
1547+
# Trying again right after that often works.
1548+
return webdriver.Firefox(
1549+
service=service,
1550+
options=firefox_options,
1551+
)
1552+
else:
1553+
raise Exception(e.msg) # Not an obvious fix.
15381554
else:
15391555
return webdriver.Firefox(
15401556
service_log_path=os.path.devnull,

seleniumbase/fixtures/base_case.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5016,7 +5016,9 @@ def js_click(
50165016
element = self.wait_for_element_present(
50175017
selector, by=by, timeout=settings.SMALL_TIMEOUT
50185018
)
5019+
scroll_done = False
50195020
if self.is_element_visible(selector, by=by):
5021+
scroll_done = True
50205022
self.__demo_mode_highlight_if_active(selector, by)
50215023
if scroll and not self.demo_mode and not self.slow_mode:
50225024
success = js_utils.scroll_to_element(self.driver, element)
@@ -5050,6 +5052,16 @@ def js_click(
50505052
action = ["js_cl", selector, href_origin, time_stamp]
50515053
if all_matches:
50525054
action[0] = "js_ca"
5055+
if not self.is_element_visible(selector, by=by):
5056+
self.wait_for_ready_state_complete()
5057+
if self.is_element_visible(selector, by=by):
5058+
if scroll and not scroll_done:
5059+
success = js_utils.scroll_to_element(self.driver, element)
5060+
if not success:
5061+
timeout = settings.SMALL_TIMEOUT
5062+
element = page_actions.wait_for_element_present(
5063+
self.driver, selector, by, timeout=timeout
5064+
)
50535065
if not all_matches:
50545066
if ":contains\\(" not in css_selector:
50555067
self.__js_click(selector, by=by)
@@ -11585,7 +11597,16 @@ def __js_click(self, selector, by="css selector"):
1158511597
simulateClick(someLink);"""
1158611598
% css_selector
1158711599
)
11588-
self.execute_script(script)
11600+
try:
11601+
self.execute_script(script)
11602+
except Exception:
11603+
# If the regular mouse-simulated click fails, do a basic JS click
11604+
self.wait_for_ready_state_complete()
11605+
script = (
11606+
"""document.querySelector('%s').click();"""
11607+
% css_selector
11608+
)
11609+
self.execute_script(script)
1158911610

1159011611
def __js_click_all(self, selector, by="css selector"):
1159111612
"""Clicks all matching elements using pure JS. (No jQuery)"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
'packaging>=21.3;python_version>="3.6"',
132132
'setuptools>=44.1.1;python_version<"3.6"',
133133
'setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"',
134-
'setuptools>=63.1.0;python_version>="3.7"',
134+
'setuptools>=63.2.0;python_version>="3.7"',
135135
'tomli>=1.2.3;python_version>="3.6" and python_version<"3.7"',
136136
'tomli>=2.0.1;python_version>="3.7"',
137137
"wheel>=0.37.1",

0 commit comments

Comments
 (0)