Disabling JavaScript dynamically in Selenium WebDriver for Firefox

While I am aware that Firefox profiles can be used to disable JavaScript, like in this example on Selenium WebDriver, I have come across a scenario where I need JavaScript enabled for logging into a page, but disabled once logged in. This way, when I use page_source, it will return the DOM without any JavaScript effects. The challenge here is that the login page specifically requires JavaScript. Is there a way to dynamically control JavaScript enablement using Selenium WebDriver?

Answer №1

It is recommended not to dynamically disable JavaScript because many functionalities of WebDriver are dependent on it, potentially leading to unexpected results. A better approach would be to use Firefox Profiles for disabling JavaScript. However, here is a code snippet that can help you disable it during runtime:

WebDriver driver = new FirefoxDriver();
driver.get("about:config");
Actions act = new Actions(driver);
act.sendKeys(Keys.RETURN).sendKeys("javascript.enabled").perform();
Thread.sleep(1000);
act.sendKeys(Keys.TAB).sendKeys(Keys.RETURN).sendKeys(Keys.F5).perform();

If you are using Selenium IDE, you can also refer to this link for more information on disabling JavaScript: .

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

Create object keys without relying on any ORM or database management systems like mongoose or mongodb

Exploring a Mongoose Object: recipe = { "ingredients": [ { "_id": "5fc8b729c47c6f38b472078a", "ingredient": { "unit": "ml", "name" ...

Running Discord.js RPC on a GTA or Minecraft server

Can a Rich Presence be hosted on a Minecraft server or an Alt:v GTA server so that all players who join have it in their status? ...

Tips for setting up a blog using nodejs and express.js

Hello everyone, I could really use some assistance. I am trying to figure out how to set up a blog using NodeJS specifically with ExpressJS, including basic functions like deleting, adding, and removing posts and comments, as well as standard authenticati ...

A step-by-step guide on crafting a customized archetype for nodeJs projects

Exploring the world of the node.js framework and looking to develop a template blueprint for node.js projects. The aim is to establish a set structure with essential folders and configuration files so that others can easily generate their own projects usin ...

Hovering over triggers tooltip flickering with Mouseover/Mouseenter interaction

When the mouseover event is triggered on the parent element, there seems to be a flickering issue when moving into the tooltip (child) element. The console log indicates that the mouseover/mouseenter event is being fired rapidly. The tooltip does not stay ...

Methods for sending data from Angular to the server and vice versa

Currently, I have an application that utilizes Express along with Jade templates. I am in the process of developing a new version of the app using Angular and client-side HTML. In order to determine user permissions within my Angular code, I require acces ...

Is there a way to use the property of an object to perform a merge sort, rather than relying on an Array?

Query About Sorting JSON Object in JavaScript In search of the most efficient method to sort a large JSON object based on a specific property, I turned to JavaScript. My initial thought was to utilize a merge sort algorithm for this task due to its speed. ...

What is the best approach to integrate setTimeout() functions in Mocha test scenarios?

I'm working on a Mocha / Node.js test and I need to introduce a delay using setTimeout before executing a specific block of code. Is there a way to achieve this? It seems that setTimeout() does not function as expected within a Mocha test case. (I u ...

"Select2 dropdown search bar vanishing act: The hunt for results comes up empty

Currently, I am dealing with a scenario involving two modals, each containing a select2 search dropdown. An issue has arisen where selecting modal one filters the dropdown data effectively. However, upon selecting modal two, although the data is filtered i ...

Tips for getting a plugin to function properly when the page is refreshed in Nuxt app

I am currently incorporating the vue GAPI plugin into my project. While it functions smoothly when navigating between pages, I encounter an error upon refreshing: vue-gapi.common.js?15fd:241 Uncaught (in promise) Error: gapi not initialized at GoogleAuth ...

Using a JavaScript variable in a script source is a common practice to dynamically reference

I have a scenario where an ajax call is made to retrieve json data, and I need to extract a value from the json to add into a script src tag. $.ajax({ url: "some url", success: function(data,response){ console.log("inside sucess"); ...

What is the method to retrieve text from a div element with Webdriver-IO?

Is there a way to extract the value from the following HTML element using Webdriver-IO for automated testing? <div class="metric-value ng-binding" ng-style="{'font-size': vis.params.fontSize+'pt'}" style="font-size: 60 ...

Top technique for creating a unique cursor image for a website

I'm looking for the most efficient way to create a custom cursor image for my CSS/HTML5 website without using Flash. Ideally, I would like to implement this using CSS rather than resorting to Javascript. If Javascript is necessary, I want to know whic ...

Error message 'Module not found' occurred when trying to incorporate Axios library into project

Hey there! I am encountering a similar issue as described in this post ('Module not found' babel error after installing axios). Despite trying all the recommended solutions, the error continues to persist: Failed to compile ./src/apis/youtube. ...

Open the iframe link in the main window

As a newcomer to this platform, I am trying to figure out how to make a link open in the parent page when clicking a button within an iframe. Currently, my code opens the link in a new window. <html> <body> <form> <div class ...

What is the best way to show an image within a div using HTML and fetching data from an API response?

I am attempting to showcase an image within a div using HTML. I utilized fetch to retrieve the JSON data from the following API: . The response contains JSON data with the image URL labeled "primaryImage". While I can display it as text, I am encounterin ...

Mesh height determines the color scheme in Three.js

After loading an STL file using the STLLoader() in Three.js and converting it into a mesh, I am interested in coloring each cube of the mesh based on its height. The goal is to achieve a visual effect similar to the one shown in this image screenshot-color ...

Encountering the "unknown encoding name" issue when initializing Selenium on a Windows environment using Ruby

An error has been popping up: lib/ruby/1.9.1/win32/registry.rb:172:in `find': unknown encoding name - CP0 (ArgumentError) whenever I try to start Selenium on my Windows 7 machine with Helios eclipse. Below is the ruby code snippet causing the issu ...

Assigning identical values to all properties of an object

Let's consider an object structured like this: myObject = { "a_0" : [{"isGood": true, "parameters": [{...}]}], "a_1" : [{"isGood": false, "parameters": [{...}]}], "a_2" : [{"isGood": false, "parameters": [{...}]}], ... }; The goal is ...

Is it possible to use jQuery to add something to the end of

There are two URLs that I am working with: http://blah.com/blah/blah/blah and http://shop.blah.com/. My goal is to take the domain from the first URL (blah.com) and concatenate it with the path (/blah/blah/blah) from the second URL, resulting in http://sho ...