JavaScript is causing issues preventing the automated test from setting the input

While creating an automation script using Ruby with Selenium, Watir, and Cucumber, I encountered a test failure caused by a change in a text field. The issue arose because a Javascript function was triggered upon interacting with the field, restricting input to numeric KeyCodes, decimals, and pasting. After this modification, only "." could be entered into the field, making it impossible to input any other value. I tried converting inputs to numerical values using methods like "to_i" and "to_f", as well as alternative approaches such as:

browser.text_field(:id, "rate").set(val)

or

browser.text_field(:id, "rate").value=(val)

or

browser.text_field(:id, "rate").send_keys :numpad1

Unfortunately, none of these methods resulted in anything appearing in the text field except for the decimal. I am struggling to find a solution to bypass or deactivate the interfering Javascript temporarily so that I can enter values programmatically, then reactivate it to maintain the integrity of the overall environment. My inquiries are: 1) Has anyone encountered a similar issue and managed to resolve it? If not, 2) How can I disable JavaScript dynamically to input values and enable it back again seamlessly?

Answer №1

If the situation calls for it, combat JavaScript using more JavaScript:

browser.execute_script("document.getElementById('rating').setAttribute('value', '54321')")

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

Is it possible to include an if/else statement within a tailwind class in React components?

I want to dynamically change the background color of a div based on a condition. If the condition is true, I want the background color to be white; otherwise, I want it to be black. Despite trying to achieve this using an if/else statement, the background ...

Sneaky spam and ads embedded within Joomla template

Today, while examining the source code of a Joomla site I am developing, I stumbled upon some hidden links that seem to be spam. I have spent an hour searching through various template files but have been unable to locate them. The hidden links in questio ...

Guide to stopping available times from cycling through an array with the help of watch功能?

I am currently developing a booking application within Vue CLI. I have made use of vue-ctk-date-time-picker for selecting the date and time. My goal is to disable certain times based on the chosen date, but I am encountering an issue. The code I have writt ...

Is there a correct way to accomplish this task? How could I go about achieving it?

Currently, I am delving into the world of react. While following along with some video tutorials, I encountered a roadblock in the request.js file. The issue popped up during the build process ./src/Row.js Line 16:45: 'fetchUrl' is not define ...

AngularJS parent selector nearest to the element

I have successfully implemented a code to close a custom popup using jQuery, but I am looking for a solution that utilizes AngularJS instead of jQuery. Can anyone assist me in finding the equivalent of this.closest() in AngularJS? I aim to hide .popOverla ...

Acquire information from a JSON formatted string

I am having trouble extracting the first name from the JSON data provided below. While I am able to display the entire string using JavaScript [ alert(data); ], I am struggling to isolate just the first names. Any assistance would be greatly appreciated! ...

Ensuring Proper Tabulator Width Adjustment Across All Browser Zoom Levels

<div id="wormGearTabulatorTable" style="max-height: 100%; max-width: 100%; position: relative;" class="tabulator" role="grid" tabulator-layout="fitDataTable"><div class="tabulator-header" role="rowgroup"><div class="tabulator-header-co ...

Enabling Bootstrap modal windows to seamlessly populate with AJAX content

I'm currently in the process of crafting a bootstrap modal that displays the outcome of an AJAX request. Below is my bootstrap code: {{--Bootstrap modal--}} <div id="exampleModal" class="modal" tabindex="-1" role="dialog"> <div class="m ...

Having trouble with PHP's json_decode function with GET variables in an object?

I am currently working with an angular code that utilizes jsonp. One issue I am encountering is related to the object variable 'o_params' in my params. Here is the javascript code snippet: $http({ method: 'JSONP', ...

Create a directive for AngularJS that utilizes SVG elements without using the deprecated

I rely heavily on directives for creating and manipulating intricate SVGs. With the deprecation of "replace" in directive factories starting from version 1.3.??, I am facing a dilemma on how to construct a valid SVG without utilizing replace: true in my di ...

What is the best approach to link an HTML document to a MySQL Workbench server utilizing JavaScript, Ajax, and PHP?

On my HTML page, users can enter the name of a movie and if it is found in the database, the name will be displayed. I am attempting to establish a connection to the MySQL Workbench Server using JavaScript, Ajax, and PHP. This is what I have implemented s ...

Shift the element within the div towards the left side

I am trying to create an animation for an element that moves to the left when hovered over, but the code I thought was correct doesn't seem to be working in my fiddle. Here is the link to the fiddle I created: https://jsfiddle.net/feb8rdwp/3/ Based ...

PHP Loop News/Image Slider with Clickable Interval Reset and Improved Unique ID Formatting

Currently, I am in the process of setting up a news/image slider on my website using JavaScript. I have the slide data coming through a PHP loop with unique IDs, which is functioning smoothly. However, I am struggling to figure out how to reset the timer/i ...

Handling multiple post requests for the same route in Node.js

I am in the process of creating a Node JS application utilizing Express JS and MongoDb. Within my index.hjs file (which uses hogan), I have integrated both a login and password recovery feature. Currently, both forms have the action set to "/" and the meth ...

Can you explain the concept of a framework operating "on top of" node.js in a way that would be easy for a beginner to understand?

If someone is new to JavaScript, how would you explain the concept of "on top of node.js" in simple programming language? I am looking for a general explanation as well as specific reference to Express on top of node.js in the MEAN stack. Appreciate your ...

Tips for leaving comments on a post

Looking to create a website where users can share messages and receive comments from others. I've successfully established an express website with Node, allowing users to add new posts. After searching on Google, I found numerous tutorials on Medium ...

The ASP.NET session encounters difficulties in refreshing itself

I have been given the task of enhancing a web application built on ASP.NET 4.0 Web Forms to alert users before their session expires, and give them the option to either continue the session or end it. To achieve this, I have implemented a confirmation dia ...

Using AngularJS to implement ngView within a custom directive

I've been attempting to implement ng-view within a custom directive, but it doesn't seem to be functioning properly and I'm not receiving any console errors. Here's the code for my directive: (function() { 'use strict'; ...

Can you customize the buttons in the operation panel of an antd image preview window?

https://i.sstatic.net/hZLOn.png I am looking to add a button that allows users to download or share the image being previewed. Is there a way to achieve this functionality? I have researched and read through the documentation but have not found a solutio ...

Discovering the email address component on a Facebook page through the use of Selenium

I've been attempting to extract the body of a specific Facebook page where an email address is located, and then retrieve the email address along with other attributes within that body. Despite using Chropath and SelectorHub in various ways, I have no ...