How to Run Selenium Tests with JavaScript Disabled
Disable page JavaScript in a Selenium Firefox session, verify the no-script behavior, and handle browser differences, remote runs, and common failures.
To run an automated Selenium test with page JavaScript disabled, use Firefox and set its javascript.enabled preference to false before building the WebDriver session. This disables JavaScript executed by the website in that Firefox session; it does not disable JavaScript in the Node.js test runner.
Selenium’s JavaScript bindings document Firefox Options preferences, and Mozilla identifies javascript.enabled as the relevant preference. Browser configuration is specific: do not assume that a generic javascriptEnabled: false capability works in current Chrome or Firefox WebDriver sessions. Selenium JavaScript API, Mozilla Firefox documentation.
Run a Selenium test in Firefox with JavaScript disabled
1. Install the JavaScript bindings
npm install selenium-webdriver
The Selenium JavaScript API currently documents Node.js 22 or newer as a requirement. Confirm the current requirement against its API documentation when setting up a new project because supported versions can change. Selenium Manager handles browser driver installation for supported setups. Selenium JavaScript API.
2. Create the Firefox session with the preference
Save this as no-js.test.js and run it with node no-js.test.js. Replace the example URL and assertion with the page and expected behavior in your test.
const assert = require('node:assert/strict');
const { Builder, Browser, By } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
async function main() {
const options = new firefox.Options()
.setPreference('javascript.enabled', false);
const driver = await new Builder()
.forBrowser(Browser.FIREFOX)
.setFirefoxOptions(options)
.build();
try {
await driver.get('https://example.com');
// Replace this with an assertion that captures the no-script behavior
// your application promises. This example checks static page content.
const heading = await driver.findElement(By.css('h1')).getText();
assert.ok(heading.length > 0, 'Expected the static heading to be present');
} finally {
await driver.quit();
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
The important step is applying the Firefox preference before build() creates the session. Selenium uses an isolated Firefox profile for WebDriver, so this setting applies to the test session rather than changing a personal profile. Avoid relying on a long-lived personal browser profile for repeatable tests. Selenium Firefox WebDriver documentation.
3. Assert the behavior you care about
A browser setting alone does not establish that the application works without scripts. Choose an assertion that reflects the actual requirement: for example, server-rendered text remains available, a form has a non-script submission path, or a script-dependent control is absent or disabled. Assertions should target stable application behavior rather than incidental markup.
For stronger coverage, consider a pair of tests: one with the normal browser configuration and one with JavaScript disabled. This makes regressions in either the standard experience or the no-script fallback easier to locate. The code above is an example, not a report that the test was run.
What “JavaScript disabled” means in this test
The preference controls JavaScript run by pages in Firefox. The Node.js process still runs JavaScript to configure Selenium, navigate, locate elements, and make assertions. Browser-side scripts may normally add content, attach event handlers, or make network requests; with page scripting disabled, the page follows whatever non-script behavior its HTML and server responses provide.
This is useful for checking progressive enhancement and basic accessibility, but it does not reproduce every real-world failure mode. A browser with scripting disabled is different from a slow script, a blocked third-party script, a content security policy error, or a partially loaded application.
Browser options and limitations
| Browser/workflow | How to disable JavaScript | Automation status |
|---|---|---|
| Firefox with Selenium | Set the Firefox preference javascript.enabled to false in Firefox Options before creating the driver. |
Automated WebDriver session; this is the documented approach shown above. |
| Chrome DevTools | Open DevTools, use its Command Menu, choose “Disable JavaScript,” then reload. | Manual inspection. Chrome documents that JavaScript stays disabled in that tab while DevTools remains open; the cited instructions do not establish this as an automated WebDriver startup setting. |
| Chrome with Selenium | Use a Chrome-specific method only if supported and documented for your exact Chrome and Selenium versions. | Do not assume the Firefox preference or a generic javascriptEnabled capability applies to Chrome. |
Chrome’s documented DevTools workflow is useful for manually inspecting a page, but it is not the Firefox WebDriver configuration. Chrome DevTools: Disable JavaScript. Selenium’s browser options differ by browser; the legacy capability material does not substantiate a shared setting for modern real browsers. Selenium documentation.
Run the session remotely
Selenium’s JavaScript API supports directing a Builder to a Selenium server URL. Configure Firefox Options on the client as in the local example, then set the server URL before building:
const { Builder, Browser } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
const options = new firefox.Options()
.setPreference('javascript.enabled', false);
const driver = await new Builder()
.forBrowser(Browser.FIREFOX)
.setFirefoxOptions(options)
.usingServer('http://selenium-grid.example:4444')
.build();
Replace the server address with the reachable URL for your Selenium server or Grid. Firefox custom profiles are packaged and transferred when creating sessions, while a custom browser binary must already exist on the remote host. Check the Firefox and remote-driver documentation for your deployment’s details. Selenium JavaScript API, Selenium Firefox documentation.
cURL, Python, and Node.js examples
The Selenium setup above uses JavaScript because the title concerns Selenium tests written in JavaScript. Selenium does not expose the same language API in cURL: cURL can make HTTP requests to a WebDriver server, but it does not replace the browser-specific Firefox Options setup. For this configuration, use a Selenium client binding that can create the Firefox session with the preference.
Python’s Selenium binding can express the same Firefox preference. Install it with pip install selenium, then run a script such as:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.set_preference("javascript.enabled", False)
driver = webdriver.Firefox(options=options)
try:
driver.get("https://example.com")
heading = driver.find_element("css selector", "h1").text
assert heading, "Expected the static heading to be present"
finally:
driver.quit()
Python Selenium Manager can manage driver setup in supported configurations. Use the official Selenium documentation for the binding and environment you deploy. Selenium documentation.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The page still behaves as if scripts are enabled. | The preference was applied after the session was created, or the test is running in a different browser/session. | Set javascript.enabled on Firefox Options before build(), and confirm the Builder launches Firefox. |
setPreference is not a function or Firefox Options cannot be imported. |
Wrong Selenium package/API usage, an outdated or incompatible dependency, or an import mismatch. | Install selenium-webdriver, use require('selenium-webdriver/firefox') in CommonJS as shown, and consult the API for your installed version. |
| Firefox or its driver cannot start. | Missing browser installation, incompatible environment, or unsupported runtime version. | Check the current Node.js requirement, ensure Firefox is available in the environment, and review Selenium Manager and Firefox setup output. |
| A locator times out or an expected element is missing. | The element may be generated by page JavaScript, or the application may not provide a no-script fallback. | Assert the intended no-script outcome. If the element should remain, provide or test server-rendered HTML or a non-script interaction path. |
| The test passes locally but fails on Grid. | The remote host may use a different Firefox version or lack a configured browser binary; custom binaries are not transferred with the profile. | Install the required browser on the remote host and verify the session capabilities and server URL. |
| A Chrome test ignores the Firefox preference. | javascript.enabled is a Firefox preference, not a universal WebDriver setting. |
Use the documented Firefox path for this test, or consult current Chrome-specific automation documentation. For a manual check, use Chrome DevTools’ Disable JavaScript command. |
Performance, reliability, and cost
Disabling JavaScript can make some pages reach a stable state sooner because scripts do not execute, but it can also leave script-created content absent and make normal application selectors unavailable. Avoid treating a shorter wait or a missing element as proof that the setting worked; assert an expected page behavior.
For repeatable results, pin project dependencies as appropriate, use an isolated WebDriver session, always quit the driver in a finally block, and keep local and remote browser versions aligned. Selenium Manager reduces manual driver setup in supported environments, but browser availability and remote configuration remain deployment concerns.
The test consumes the resources of the browser and WebDriver environment you run. No pricing or execution-time figure is implied here; measure it in your own CI environment if those limits matter.
Or skip the browser setup
If your goal is to capture what a page looks like, ScreenshotNeo provides a website screenshot API and MCP server. It returns PNG, JPEG, WebP, or PDF from one GET request. ScreenshotNeo is not a replacement for a Selenium assertion about no-script behavior; use it when you need a rendered-page capture.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation. Cookie banners, newsletter popups, and chat widgets are removed before the shot; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are never billed, and response headers indicate the page verdict and billing status. An MCP server provides screenshot tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan. Learn more at ScreenshotNeo.
Sign up for 1,000 free screenshots a month, with no card required.
FAQ
Does this disable JavaScript in Node.js?
No. It disables page JavaScript in the Firefox session. The Node.js test runner continues to execute the Selenium code.
Does the preference affect my normal Firefox profile?
WebDriver uses an isolated session profile. Set the preference through Firefox Options for the test session rather than changing a personal profile.
Can I use this to prove my site is accessible?
It can check one aspect of progressive enhancement, but it is not a complete accessibility audit. Test the specific keyboard, semantic HTML, and assistive technology requirements that apply to your site.
Can I use the same setting in every browser?
No. The preference shown here is Firefox-specific. Use browser-specific documented configuration for other automated browsers.


