How to turn off JavaScript using Selenium WebDriver?

Recently, I encountered a problem with my program that tests some of our sites with javascript disabled. Everything was working perfectly until we upgraded from WebDriver 2.4.5 to the latest version. Now, I'm faced with this error message:

java.lang.IllegalArgumentException: Preference javascript.enabled may not be overridden: frozen value=true, requested value=false

It appears that disabling JS is no longer allowed with the latest WebDriver update. Unfortunately, downgrading isn't an option due to compatibility issues with our updated Firefox browser.

I'm looking for suggestions on how to test with JS disabled. Chrome never worked before, and now Firefox doesn't either. I've tried searching for solutions using "webdriver js disabled," but all I find are references to the javascript.enabled, false argument which is no longer effective.

Answer №1

Here's a suggestion to enhance browser automation with Selenium:

Start by creating a specialized Firefox profile named NoJs

Access about:config and disable javascript specifically for this profile

Integrate this customized profile into your Selenium script as follows:

ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("NoJs");

WebDriver driver = new FirefoxDriver(profile);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Selenium's @FindBy annotation - when and how should it be utilized?

After spending time diving into the Selenium API documentation on FindBy, I came across two lines of code that piqued my curiosity. @FindBy(id = "foobar") WebElement foobar; @FindBy(how = How.ID, using = "foobar") WebElement foobar; Testing both of thes ...

What causes Chrome to crash when dealing with lengthy tail files?

My objective is to display a log file in real-time using a websocket connection. However, I am facing performance issues with Chrome when the paragraph ('p') element in the HTML becomes large (about 450 lines). This is the current implementation ...

Choosing an option in a dropdown menu during ProtractorJS end-to-end testing

I need to automate the selection of an option from a dropdown menu for angular end-to-end tests using protractor. Below is the code snippet for the select option: <select id="locregion" class="create_select ng-pristine ng-invalid ng-invalid-required" ...

Automated pagination in Jquery running seamlessly

I have successfully created pagination using jQuery. Although the script is functioning properly, I now want it to automatically switch between different pages: <script> $(document).ready(function(){ $("#article_load_favourites").load("indexer_favo ...

Query a MongoDB collection by applying filters using data from a separate collection

Being new to MongoDB, I have created the following schemas: const postSchema = new mongoose.Schema( { content: { type: String, required: true, index: "text" }, author: { type: ObjectId, ref: "User", required: true, i ...

A computed property declared inside a Vue component definition

I'm currently diving into Vue.js 2 and I have a goal of crafting a unique custom component in the form of <bs-container fluid="true"></bs-container>. My intention is for Vue.component() to seamlessly handle the bootstrap 3 container classe ...

Can a JavaFx application be developed independently to utilize Spring Jdbc and connect to a Mysql database?

I am currently facing a challenge as a beginner in JavaFx and Spring JDBC. My application is nearly complete, and I have successfully created an installation file for Windows using Inno Setup. However, when I try to run this installation file on another sy ...

Does Selenium Java have a specific method to obtain the body tag for WebElement class?

My goal is to extract the body of pages from an HTML source. I have been attempting to do this using the WebElement Class. However, I am encountering issues accessing the invisibilityOfAllElements method as it keeps throwing errors. Here is the code snippe ...

Tips for submitting the following query using RestAssured with Selenium

What is the correct way to POST the request below using RestAssured with Selenium? The request includes: { "ShipmentID": "", "ShipmentNumber": "123455-6", "Comments": "", "LineIDs": [ { "ShipmentDID": "", "AssetNum": "7595 ...

What method can I use to grant Drools permission to interact with dynamically loaded classes?

My current project involves using a custom ClassLoader to dynamically load classes from .class files at runtime and utilize them in Drools rules (version 7.52.0). The ClassLoader I am using reads from a file and employs the ClassLoader.defineClass() method ...

Generate the JavaScript file only if the Typescript file is error-free, to ensure a smooth compilation process

Take a look at the following TypeScript code snippet: class formal { private startString: String = ""; constructor(startString:String) { this.startString = startString; } public sayHello = function() :Number { alert(thi ...

Understanding how to set a specific tab based on the URL in a jQuery tab script

How can I modify my jQuery search script to ensure that only the type is considered when a URL is created with #type/query/? Even if there is a query included in the URL, I want the corresponding tab to appear selected. Can someone help me understand how t ...

Angular directive does not focus on the text box

I've been working on creating text boxes using a directive and I want only the first text box to be in focus. To achieve this, I am utilizing another directive for focus control. Below is my script: <script> angular.module('MyApp',[]) ...

Input a new value into the registration field to update it

My current task involves adding a new text field to a React form using a button. I need this new input text field to be able to store data on a register. How can I go about setting this property? Typically, when creating a text field, you would utilize co ...

The continuous firing of the postback event of the Asp.Net Button is

Why does the postback event keep firing for my button? Strangely, when I try to debug with Firebug and set a break point on the function(e) part, the code seems to skip right over it. Even using return false doesn't seem to resolve the issue. <sc ...

Verification of email address is required, emails must be unique and not duplicated

I am working on validating email addresses to ensure they are not repeated. So far, I have successfully pushed them from the server into an array using regex for validation. What steps should I take next to compare and further validate these emails? ...

Is it possible to vary the font size for different fonts within a single page?

Imagine using Helvetica for English text and a unique, exotic font (from an ASCII perspective) for another language on the same page. Even with the same font size, one font may appear larger to the eye. Is it possible to specify different font sizes for ...

Tips for crafting effective error messages to communicate with users

One of the biggest challenges I face is crafting clear error messages for clients in case of errors. A typical scenario involves using Axios and a third-party API to fetch data, requiring appropriate error handling for both. Axios' error handling doc ...

parse website using jsoup redirection

While parsing data from this URL, I encountered an issue with the ajax load process. Despite my efforts to parse the website, I only receive the body element and not the desired response within the ticket_lists. I am unsure how to tackle the redirection on ...

The success function of the Ajax request remains untouched by the response

My ajax call isn't triggering the success:function(resp){ ...} Despite receiving a response status of 200 and a non-null Json response. This is my ajax setup: $.ajax({ url: '/url/', type: 'GET', data: { pass_ ...