Issue with Ruby Selenium Webdriver: Unable to locate attributes for AngularJS Radio Buttons

I am having trouble detecting the presence of the "checked" attribute on a radio button.

Here are the two radio buttons in question: Radio Buttons

These are the attributes of the elements:

<input type="radio" ng-change="logConsent(true)" ng-model="xxxConsent" value="true" id="xx_Summary_Radio_Consent_Yes" name="consent" class="ng-valid ng-dirty">

and

<input type="radio" ng-change="logConsent(false)" ng-model="x2Consent" value="false" id="x2_Summary_Radio_Consent_No" name="consent" class="ng-valid ng-dirty">

When using Selenium webdriver, element.attribute('checked') always returns nil. I am unsure of how to determine if these radio buttons are checked or enabled. I attempted to monitor changes through Chrome inspect, but the attributes remained the same before and after checking the radio buttons. Can anyone assist me in verifying this?

To moderators and users: I have not been able to find relevant information related to my radio button issue on StackOverflow despite numerous similar questions. That is why I am posting a separate inquiry.

Answer №1

It seems like the HTML contains some valuable attributes.

To keep track of these clicks, consider using an event directive to monitor them and determine if they are true or false. This will help generate the desired history you mentioned.

You might want to set up an event listener for ng-dirty or any other triggering event specified by the developer. Seek assistance from the developers on this matter. By monitoring triggered events, you can confirm that the click function is working properly based on the values being read as true or false. While this method confirms a click event and the presence of an HTML node attribute value, it does not directly verify the checked attribute itself.

Answer №2

According to the provided HTML code, there is no 'checked' attribute present yet you are attempting to retrieve it. This is why you are receiving null values. Based on the HTML provided, there should be a 'value' attribute with a value of True for one option and False for another. Therefore, I expect the checked radio button to have a value of "True", so try using the value attribute instead.

In Java, you can attempt the following:

myWebElement.getAttribute("value"); // this will retrieve true or false

// alternatively, you can also try the following:

if(myWebElement.isEnabled() == true) {
    // my element is in a selected state
}

Thank you, Murali

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 is the best way to determine the left and top coordinates when resizing a draggable image within a container?

I am struggling to correctly scale the image and set the left (x) and top (y) positions. Here is the code from my template: <div id="container" :style="`height: ${height}px;width: ${size}px;overflow: hidden;position: relative;`"> ...

Auto language-switch on page load

Wondering if using jQuery is the best approach to create a single French page on my predominantly English website. I want it to work across multiple browsers on pageload, currently using HTML replace. jQuery(function($) { $("body").children().each(funct ...

Error encountered when installing angular 8 components due to package conflicts

Having Trouble Building .NET Core + Angular Project I have encountered an unfamiliar project that requires minor fixes. I attempted to build it with the following command: dotnet publish -c Release -r win-x64 --self-contained false --output "D:&bso ...

When I click on the icon, I wish for it to revert back to its original state by spinning

Is there a way to revert the icons back to their original state when clicked again, without losing any of the current functionalities? When an icon is clicked for the first time, it rotates 180 degrees. The icon rotates back if another icon is clicke ...

The existence of an array within a grid maintained as a property of a single item

I'm facing an issue with displaying array instances in a grid connected to a store with a model. The type property is set to 'auto' for the array in the model instance. How can I adjust the settings to show all the array instances correctly ...

Keeping data external to promises in protractor

In my angular app, I have a timeline feature that displays the names and descriptions of players. All player names are under the common class player-title.ng-binding, while all player descriptions share the class .player-description.ng-binding To retrieve ...

"Implementing an ellipsis feature in Highcharts to handle lengthy data gracefully

Looking for some help with adjusting the positioning of a pie chart on the page. The data on the left and right sides is not displaying correctly, so I want to center the chart and add ellipsis for any overflow. Check out the code here: http://jsfiddle.n ...

What is the best way to create an XPath query that combines a starts-with and does not end-with attribute?

Currently creating an XPath query. Developing a script and attempting to locate a specific element on the webpage. ...

Exploring the interaction between child objects and cube objects in Three.js

I have a main cube object with wireframe: var cubeGeometry = new THREE.CubeGeometry( 50, 50, 50 ); Also, I have some cubes that are not wireframed: var cubeTemp = new THREE.CubeGeometry( 10, 10, 10 ); I want to rotate cubeGeometry and have cubeTemp rot ...

The feature of using a custom find command in Cypress does not support chaining

I am interested in developing a customized Cypress find command that can make use of a data-test attribute. cypress/support/index.ts declare global { namespace Cypress { interface Chainable { /** * Creating a custom command to locate a ...

Upon clicking the Submit button in Selenium Webdriver (Java), the passwords field is cleared and the flow is halted

I am encountering a problem in IE11 while using Selenium in Java. After inputting the username and password into the fields, when I click the Submit button, the password field is cleared and the automation process cannot proceed. Even though it works fine ...

Storing the results of an Ajax call in a global variable

What is the best way to store and access the output of an ajax call within a global variable? let globalOutput = []; $.ajax({ type: "GET", url: uri, dataType : "json", contentType: "application/json", data: { input: filterVa ...

AngularJS - A pagination demonstration incorporating intelligent logic inspired by Google's approach

I struggled to implement a paging solution that I came across online. The issue seems to be related to the timing of function calls, specifically how the setPage function is triggered before all data is retrieved, causing it to not properly determine the t ...

Retrieving information from Firebase using React

Is there a way to retrieve data from Firestore? import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; import 'firebase/compat/firestore'; const firebaseConfig = { apiKey: "AIzaSyCNBAxjeKNoAPPjBV0 ...

Utilizing Angular 5: Enhancing ngFor with a Pipe and a Click Event

Iterating through an array of objects using *ngFor, I apply various filters via pipes to manipulate the resulting list. One of these pipes relies on a user input from a search field. Upon clicking on one of the ngFor elements, the corresponding object is p ...

What is the process for transferring a PDF document to the frontend?

I have a file saved in .PDF format on my computer, and I am attempting to send it to the frontend using node/express. Although I am able to successfully send the file as a binary string stream to the frontend, when trying to download the .PDF onto the use ...

Triggering a click event on various instances of a similar element type using the onclick function

Hey there, I'm a newcomer to Javascript. I've been practicing my Javascript skills and trying to replicate something similar to what was achieved in this example: Change Button color onClick My goal is to have this functionality work for multip ...

Most efficient method for implementing a recursive function while looping through elements in an array

Let's consider a scenario where we have an array of letters: const letters = ['a','b','c','d']; In addition, we have a function that requires a string argument letter and generates a concatenated output of that ...

Having trouble iterating over a JSON object in a Node.js application

I am struggling with looping through a JSON object using NODEJS. Specifically, I am attempting to access the values like var value = [table][row][0][STATE] or [table][row][1][STATE] or [table][row][2][STATE], but I keep encountering an error saying STATE ...

Is your Angular5 service failing to transmit data?

I have two components in my code, A and B. Component A contains a form with data that I want to send to component B. However, it seems like component B is not receiving any data. Here is the code for Component A: import { MyService } from 'path/my ...