Selenium struggling to run Javascript code on a webpage

I am facing an issue where my JavaScript code is not executing on my page(s) through Selenium.

Here is the code I am using:

// Setting up a driver instance for Chrome
IWebDriver driver = new ChromeDriver();
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

driver.Manage().Window.Size = new Size(1100, 1100);
driver.Navigate().GoToUrl("http://www.google.com/");
js.ExecuteScript("function reloadScrollBars() { document.documentElement.style.overflow = 'auto'; document.body.scroll = 'yes';} function unloadScrollBars(){ document.documentElement.style.overflow = 'hidden'; document.body.scroll = 'no';}");

I am seeking insights from anyone who might know why this code is not running as expected.

Answer №1

Success! It's working

js.ExecuteScript("return document.body.style.overflow = 'hidden';");

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

What causes the Redux store to clear out in Next.js when transitioning between pages?

On my initial page, I utilized the getServerSideProps function to call an API which returned two IDs - id-A and ID-B. Now, on my second page, I need to invoke another API using the getServerSideProps function and pass those IDs as parameters. How can I ach ...

How can you determine when a download using NodeJS HTTPS.get is complete?

Currently, I am facing an issue while downloading a file. My goal is to perform an action immediately after the download is complete. Specifically, I aim to import a .js file as soon as it finishes downloading. var request = https.get('https://m ...

Retrieve values from an array containing objects using JavaScript

As I am exploring Firebug, I encountered an issue where the console log of an array shows: Array [ ] Even though in the right panel of Firebug it is visible that the array contains 3 objects, I am unable to access them. Is there a way to retrieve these va ...

Executing Continuous Process using Node.js

I am currently working on a server project that involves streaming webcam footage and other functionalities. Everything is set up within my node.js server, with an HTML page that includes a select drop-down menu linked to a JavaScript function via socket.i ...

Organizing DataFrame Display | Selenium Automation | Python Development

I have successfully set up a script to iterate through a list of URLs. However, I am facing challenges in generating a cleaner CSV output with the current setup. I am open to any suggestions that can help streamline the process of formatting cleanup, Exce ...

I kindly ask for your assistance in sharing your selenium rc code

Similar Query: XPATH or css in selenium RC I am attempting to automate a task using Selenium RC and Java. The steps are as follows: 1. Navigate to the Google homepage 2. Enter "software" in the search text box 3. Click on the search button 4. Click o ...

All static functions in Selenium Webdriver can be accessed through a single line

var findById = driver.findElement(By.id("id")) var findByClass = driver.findElement(By.className("class")) var findByXpath = driver.findElement(By.xpath("xpath")) Is there a way to simplify the above code into one line like this: var dynamicLocator = "id ...

The functionality of jQuery mobile seems to be interrupted when attempting to load data from a JSON file into a list

I'm enhancing my skills in JQueryMobile and JavaScript through the creation of a basic web application that retrieves data from a json file and displays it in an interactive listview. The objective is to click on one of the li elements which will the ...

Unable to invoke setState on an unmounted component in a React application

For some reason, I keep encountering a warning when trying to update the value of an input field. The warning states: "Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Ins ...

Changing a div's properties is causing jQuery to behave strangely

Something strange happened while coding in javascript, especially with some jquery functions. Check out my code below <?php // Encoded in UTF-8 if(isset($_SESSION['username'])) { ?> <script type="text/javascript"> funct ...

The order of event handlers in jQuery

I am currently setting up event binding for a text element dynamically. Take a look at the following code snippet: <input type="text" id="myTxt" /> <script type="text/javascript"> function attachEvent1(element){ element.keyup(func ...

Dealing with xmlhttpResponse containing HTML code and the necessity to manipulate anchor elements

`var dataResponse = xmlhttp.responseText; $(dataResponse).$('#products href').each(function(){ this.href = "http://www.samplewebsite.com" + this.href; }) ` The dataResponse variable stores html co ...

What is the process of generating enum values using ES6 in Node.js?

Can JavaScript support enumerations with assigned integer values, similar to how other programming languages handle it? In C#, for instance, I can define an enum as follows: enum WeekDays { Monday = 0, Tuesday =1, Wednesday = 2, Thursday ...

After updating the INNERHTML, the NAV tag content is no longer functional

I am facing an issue with replacing the contents of a NAV tag that contains UL list items. The original HTML within the NAV tag works perfectly fine, but when I replace it with my own HTML - which matches the original word for word - the dropdown functiona ...

Different ways to trigger events with the press of a single button

Is there a way to send an event to the backend where 'isVerified' can be true or false based on the last condition, with only one button form available? <form onSubmit={(ev) => this.submit(ev, 'isVerified')}> ...

Setting up a Node.js application with Nginx on DigitalOcean

While running my application on a DigitalOcean droplet using nginx, I encountered a peculiar issue. The app runs perfectly fine with http, but when switching to https, nginx throws a 502 BAD GATEWAY error. Despite trying various DigitalOcean guides and sco ...

What is the process for incorporating a function into the prototype of an interface that functions as a class?

Adding a function to the prototype of a value is simple. For example: Array.prototype.removeAt = function (index) { if (index >= 0 && index < this.length) { this.splice(index, 1); } return this; }; declare global { export interfa ...

Incorporating image hyperlinks onto a designated webpage within a JavaScript presentation carousel

Working on an e-commerce website, the client has requested 3 slide shows to run simultaneously displaying specials or promotions. I have successfully set up the 3 slide shows next to each other, but I'm unsure how to incorporate image links that direc ...

What is the best way to transform an array of strings into a JSON object?

When navigating back to a list page, I want to make sure that the filter criteria are still retained. My solution involves using cookies, which are set when the form filter is submitted. In the list page's mounted hook, I retrieve the specific cookie ...

I'm trying to set an object value for this select element, and while I have managed to do so, I am struggling to display the title of the selected object. Can anyone help me

I am struggling to display the title of the selected object in this select element. Can anyone help me understand why my code is not showing the title? Here is the code snippet: const [selectedCategory, setSelectedCategory] = useState(""); const categor ...