Having trouble activating the onclick event on a radio button

In my testing framework, I have implemented a keyword-based approach using Selenium 3.x and Java. One of the web elements I am working with is:

<input id="radiobutton" name="webserviceBarFlg" onclick="setReadOnly(this)" class="foo-input-radio-margin foo-input-radio" type="radio" value="true" checked="checked">
<input id="radiobutton" name="webserviceBarFlg" onclick="setReadOnly(this)" class="foo-input-radio-margin foo-input-radio" type="radio" value="false" checked="checked">

There is a JavaScript method that affects other input elements.

function setReadOnly(obj) {
    var varRadio = $(obj).val();
    var input = $(obj).closest("tr").next("tr").find("input");
    if(varRadio == "false") {
        $(input).attr("readOnly", true);
    } else {
        $(input).attr("readOnly", false);
    }
}

I have experimented with two solutions on Internet Explorer 11, Windows 10 Pro:

Solution 1

webElement.click();

Solution 2

private RemoteWebDriver remoteWebDriver;
//...

JavascriptExecutor executor = (JavascriptExecutor) remoteWebDriver;
executor.executeScript("arguments[0].click();", webElement);

However, I am still unable to trigger the onclick event. Any suggestions on how to achieve this?

Answer №1

To make it work correctly, remember to create the setReadOnly(this) function.

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

Verify if the loading spinner is currently visible on the tab

I've included a download button on my website for users to easily download a file. When the user clicks on the button, the page begins loading, as indicated by the tab: https://i.sstatic.net/9DkM8.png Is there a way to determine the state of this p ...

Disable form input fields while keeping all other elements enabled

Currently, I am facing a dilemma where I must deactivate specific input fields within a form. Given that there are numerous fields to consider, individually disabling each one seems impractical. Can anyone offer advice on how to disable a set of elements ...

Trying to populate an array with user input from the console, but every second element ends up getting set as an empty value

I'm encountering an issue while trying to populate an array with console input and then display it in reverse order. For some reason, every other element is being assigned a blank value, resulting in missing lines of input during output. The current a ...

Error in syntax: missing comma after property identifier in MongoDB shell at line 4, position 5

Having trouble with a syntax error Getting error message "missing after property id@shell:4:5" db.movieDetails.updateOne({ title:"The Martian" } , { $set { poster:"http://howle.jpg" } }) db.movieDetails.updateOne({ title ...

Updating JSON objects in jQuery with string keys

I have an array variable containing JSON data and I need to update specific values within the array using string keys. Here is a snippet of what my array looks like: { "all": [ { "image":{ "URL":"img/img1.jpeg", ...

What's the reason for fadeIn() not functioning properly?

Here's the HTML code I'm working with: <!DOCTYPE html> <html> <head> <title>Furry Friends Campaign</title> <link rel="stylesheet" type="text/css" href="styles/my_style.css"> </head ...

React JS BlueprintJS Date Range Picker not functioning as expected

I am struggling to implement a DateRangePicker using BlueprintJS on my component, following the instructions in the documentation. I also want to include a RangePicker similar to the one shown in this screenshot. I have successfully installed all the nece ...

"Learn the process of sending a post request using a combination of JQuery, Ajax

I am attempting to send a post request with the following code - var app = angular.module('myApp', []); app.controller('myCtrl', function ($scope) { $scope.data = {}; $scope.reqCalling = function () { ...

Extracting a small handful of names from a vast pool of data

I created a web scraper using Python and Selenium to extract all the product names from redmart.com. However, every time I run the code, it only retrieves 27 names even though there are many more on the page. The website uses lazy-loading which might be ca ...

HTML Buttons Remain Selected After Being Clicked

Currently working on a calculator app for a class project but I've hit a roadblock while setting up keyboard listeners. The keyboard functionality is fine, however, when it comes to clicking on buttons, specifically the non-keyboard functions, they re ...

issues with the functionality of bootstrap modal

I'm currently working on a project where I need to set up a modal popup using bootstrap. The website I'm working on is organized by departments, so the only part of the code that I have control over is the main body of the site. I have included t ...

Button functions properly after the second click

import { Input, Box, Text, Divider, Button } from '@chakra-ui/react'; import { useState } from 'react'; export default function GithubSearchApp() { const [username, setUsername] = useState(''); const [data, setData] = use ...

Vercel Alert: (Azure) Missing OpenAI API key

After successfully implementing the openAI API in my Next.js application using the langchain library, everything worked flawlessly on localhost. However, upon deploying to Vercel (ProVersion), I encountered an error: Error: (Azure) OpenAI API key not fou ...

Retrieve and save only the outcome of a promise returned by an asynchronous function

I am currently working on an encryption function and have encountered an issue where the result is returned as an object called Promise with attributes like PromiseState and PromiseResult. I would like to simply extract the value from PromiseResult and s ...

What is the best way to convert a string value such as '20180131T120000Z' into a Date object?

Can anyone help me figure out how to parse the following String date format (yyyyMMddThhmmssZ) to Date? const date = Date.parse("20171201T120000Z"); console.log(date); The result I'm getting is NaN. What would be the most efficient method to achieve ...

Updating a div's border using JavaScript

I recently generated a div element dynamically through code. var Element; Element = document.createElement('div'); My goal now is to modify the right and bottom borders to "#CCCCCC 1px solid". I aim to achieve this without relying on any exte ...

Caution: The React Hook useEffect is missing a dependency: 'postImage'. Make sure to include it or remove the dependency array before running npm run build

Every time I run the npm run build command in my project, a warning message is displayed stating that Warning: React Hook useEffect has a missing dependency: 'postImage'. Either include it or remove the dependency array. react-hooks/exhaustive- ...

The Angular framework's structure is loaded in a combination of synchronous and asynchronous ways once the primeng tableModule

Encountered this error while trying to load the TableModule from primeng into my components module file and running 'npm run packagr': Maximum call stack size exceeded To address this, I switched my primeng version from primeng12 to primeng11.4. ...

Is there a way to change the background color of a redirected page by clicking on a tag?

I have a specific goal in mind: when clicking on an anchor tag, it should redirect to page2.html and change the background color of a particular div on that page. (The anchor tag contains a URL and an ID in its href to direct to a specific section.) pa ...

Using Angular JS to compare and display the changed value in a textbox from its previous value

This is the code I am working with <body> <div> <table ng-app='myApp' ng-controller="MainCtrl"> <thead></thead> <tbody ng-repeat="prdElement in palletElement track by $index&quo ...