Determine the type of element existing in the table cell

Currently, I am utilizing protractor to iterate through table cells in an attempt to verify the presence of a checked checkbox.

var elements = element.all(by.css(columncssname));  
elements.each(function (cell, index) {
     <--need to confirm if checkbox is displayed and checked here -->
});

Is there a way for me to establish whether there is a checkbox element within this cell?

Do you have any suggestions or ideas on how to accomplish this task?

Answer №1

If you want to determine if an element is displayed, the isDisplayed() function can be utilized. Similarly, the isSelected() function can be used to check if an element is checked. In a scenario where there are multiple checkboxes, one in each cell, here's a method to verify them -

var elements = element.all(by.css(columncssname));
var checkboxElement = $('SUB_LOCATOR_FOR_EACH_CHECKBOX_IN_CELL');
elements.each(function (cell, index) {
    expect(cell.checkboxElement.isDisplayed()).toBe(true); //Confirm checkbox visibility
    cell.checkboxElement.isSelected().then(function(selected){
        if(selected) console.log('Element Selected'); //Prints element selection confirmation to console
    });
});

Another approach to checking if an element is checked involves using the filter() function in combination with the count() method to determine the number of checked checkboxes. Here's how it can be done -

var checkboxElement = element.all(by.css('LOCATOR_FOR_ALL_CHECKBOXES')); //Use a universal locator for all checkboxes instead of a sub-locator specific to table cells
checkboxElement.filter(function(eachCell){
    return eachCell.checkboxElement.isSelected().then(function(selected){
        return selected;
    });
}).count().then(function(count){
    console.log(count); //Displays the count of checked elements
});

I hope this information proves beneficial.

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

Populate your HTML with JSON data

I need some guidance on how to achieve a specific task. I have a PHP file that retrieves data from a MySQL database and returns it in JSON format. Now, I want to display this data in HTML with "data_from_json" replaced by "18.5". Any assistance would be gr ...

Click on the link to open it in a SharePoint modal and populate it with the value from the

After populating a ng-grid with SharePoint items, my goal is to have the SharePoint edit form open in a modal window when the edit button at the end of each row is clicked. However, I am encountering difficulties when using OpenPopUpPage as the {{row.entit ...

The Webdriver is encountering an issue where it is unable to interpret the element, resulting in a Null

I am currently working on automating a test sequence that involves the steps of login, booking, and cancellation. Everything works fine up to the booking stage, but once it reaches the cancellation part, I encounter a java lang NullPointer Exception. I hav ...

What is the process for launching multiple instances of Google Chrome on various remote debugging ports?

When connecting Selenium to an existing Chrome session, I open Chrome using the command: "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir="C:\selenium\Ch ...

"Simultaneously updating the UpdatePanel, triggering a JavaScript postback, and modifying the querystring in a SharePoint Search

Struggling with a tricky issue here. Let me try to clarify: I have a SharePoint results page where I'm using a Search Results Core WebPart. Now, I want to modify the parameter in the querystring upon postback so that the WebPart displays different re ...

Creating dynamic tooltips with AngularJS

UPDATE: It appears that there may be an issue with the scope not updating when the email field is invalid. Is there a way to change that behavior? This is my first time posting on stackoverflow so I hope I'm doing it correctly. I am new to AngularJS ...

What is the reason behind the automatic activation of a function when a nested React modal is

I've been experimenting with using react-responsive-modal and then switching to react-modal, but I'm encountering the same issue. Additionally, all my forms are built using react-hook-form. The problem arises when I have one modal triggering ano ...

Retrieve distinct keys from a JSON file in Node.js

Below is an example of JSON data: [ { "Name": "User1", "primaryRegion": "US" }, { "Name": "user2", "primaryRegion": "US" }, { "Name": &q ...

Tips on showing a response in an HTML node with Node.js and AngularJS

Just starting out with NodeJS and AngularJS. My goal is to fetch a response from an external site and display it in Angular JS. I managed to send the request and receive a response, but on the UI JSON appears as a string with forward slashes "\". For ...

Updating a JavaScript global variable within a click event function: A quick guide

I am currently using Javascript and jQuery to retrieve the mouse coordinates of a click event for use in other Javascript functions. The issue I am facing is that global variables set within an event function do not update outside the function, unlike glob ...

The error message "element is not defined" is indicating an issue related to the cordova-plugin-google

In my current project using Ionic 3, I decided to implement map-related features by incorporating the Google Maps plugin recommended by the Ionic Team. This specific plugin serves as a wrapper around cordova-plugin-googlemaps. Following the steps outlined ...

Problem with OnClick function in Firefox

I have implemented the following code in an external JavaScript file: $( document ).ready(function() { var elem='<img class="imgload" src="/common/images/spinLoader/transperent.png">'; $('.imgchange').append(elem); }); $(func ...

Issue: A child component's function is unable to update the state of the parent component

I have been working on a project using React. Below is the code for the parent component: class Parent extends Component { constructor(props) { super(props); this.state = { deleteConfirm: false }; } onDelete = pass => { thi ...

The unrevealed node that is requesting the module is leading to an undefined outcome

I'm facing an issue where I need to import var server = require('../../index.js'); in my foo-dao.js file. This is necessary for accessing a hapi server plugin without passing it through the hapi request object from controller to dao. The pr ...

What steps should I follow to incorporate channel logic into my WebSocket application, including setting up event bindings?

I'm currently tackling a major obstacle: my very own WebSocket server. The authentication and basic functionality are up and running smoothly, but I'm facing some challenges with the actual logic implementation. To address this, I've create ...

Mapping nested values from a Typescript object to properties of a JSON object

Within the scope of a current project I am involved in, we have opted for utilizing the Angular toolset identified as formly to dynamically generate our forms. The present configuration of the form is hardcoded into a Typescript object denoted as mockForm ...

Accessing React Context globally using the useContext hook

I'm feeling a bit puzzled about how the useContext hook is intended to function in a "global" state context. Let's take a look at my App.js: import React from 'react'; import Login from './Components/auth/Login'; import &apos ...

Navigating a JSON message received from a websocket: Best practices

How can I cycle through various types of JSON messages received from WebSocket and trigger a function based on the type to modify observables in MobX? Can anyone assist with this? For instance, one of the simple messages looks like this: { name: "as ...

What is the process for eliminating the invocation of a function in Jquery?

I am currently facing an issue with my application. When I launch the Ficha() function, it initiates an ajax call and works perfectly fine. However, another ajax call is made later to load HTML tags that also need to invoke the Ficha() function. The prob ...

I Tried Adding Up All the Numbers, but It Doesn't Seem to Work for Every Dynamic Total Field

In my project, I am utilizing Laravel 5.7 and VueJs 2.5.*. The issue I am facing is that when I input values, the Total field calculates correctly. However, when I dynamically add rows for items, the calculation only works for the first row and not for the ...