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

Create a set of n randomly generated points, represented as latitude and longitude pairs, originating from the central point of a polygon while remaining within the boundaries

I am currently trying to plot data within a polygon (District), but unfortunately, I do not have specific coordinates for each of the data sources in that district. My goal is to accurately display all the results from a district within its boundaries, wh ...

Preventing Flash of Unstyled Content in ElectronJS Browser Windows

Upon creating a new BrowserWindow and utilizing loadURL to incorporate an html file within the renderer, there is a brief instance where unstyled content is displayed for approximately half a second before the css is loaded. window.loadURL('file://&a ...

Issue with onClick event not functioning properly in a React / Next.js component that is nested

I'm struggling to make the hideMoreDetails() function work on this component. Whenever I click on the 'close-more-info-cross' div, nothing gets logged in the console and the state remains unchanged. Any thoughts? Could it possibly be a stac ...

Take screenshots using Allure reporter only in case of a failure

I followed a tutorial on how to integrate screenshots with tests using the Allure Jasmine framework from https://github.com/allure-framework/allure-jasmine. However, I am currently facing an issue where a screenshot is captured after every spec run, even i ...

Various issues arising from a single input in Foundation Abide with AngularJS

Trying to set up a form using Foundation has proven challenging, especially when it comes to implementing more advanced error checking. If we take the example of an input field like this: <input pattern="username" required type="text" placeholder="user ...

Differences in Function Scope: A Comparison of ECMAScript 6 and ECMAScript 5

What are the advantages of ES6 compared to ES5 when it comes to block scope functions? Although the blocks may look similar in both cases, what impact does it have performance-wise and which approach is more efficient? ES6 Block { function fo ...

Filter an array of objects recursively based on various properties

I need help filtering an object with nested arrays based on specific criteria. Specifically, I want to filter the main array by matching either RazaoSocial:"AAS" or Produtos:[{Descricao:"AAS"}] This is my code: var input = [ { RazaoSocial: 'AA ...

Select one href by clicking and apply addClass

I have a one-page HTML document with links in the header. I want to make it so that when I click on a link (<a>), only that specific link changes its class to (.links). I've tried various methods, but the current jQuery method I'm using ad ...

Creating an interactive time selection tool with two dropdown lists that are dependent on each other using HTML and JavaScript

Hi everyone, I am new to JavaScript. I am currently working on creating two dropdown lists, one for 'Start Time' and another for 'End Time'. These dropdown lists will display hours in a 24-hour format with intervals of 30 minutes. In t ...

Navigating the process of transferring a function to a functional component within React

Hey there, I'm fairly new to using React and TypeScript and I am facing a small issue with moving a function from the file App.tsx to a functional component called WordAddingForm.tsx. Any help would be greatly appreciated! Let's start with my Ap ...

Start from scratch when establishing the baseline for "defaults."

Struggling to reimagine the _.defaults function from underscore.js, I keep encountering this pesky error: Error message: should copy source properties to undefined properties in the destination object‣ AssertionError: expected { a: 'existing' ...

Troubleshooting a jQuery carousel: How can I prevent the thumbnails from automatically moving forward?

I am currently modifying a carousel where the thumbnails are moving out of frame. I need assistance in keeping them stationary, except for the blue thumbnail highlighter. To better illustrate the issue, I have created a jsFiddle here: http://jsfiddle.net ...

Can you explain the significance of a single variable line in JavaScript?

While reading a book on Angular.js, I came across the following syntax: $scope.selectedOrder; // What does this syntax mean? $scope.selectOrder = function(order) { $scope.selectedOrder = order; }; I understand that selectedOrder is a property of the $s ...

Python scraper causing CPU to run uncontrollably on T2.micro instance

I currently have a web scraping tool set up on a t2.micro EC2 instance operating with Ubuntu. This particular scraper is coded in Python, utilizing Selenium and PhantomJS for its functionality. The extracted data is then directed to a separate RDS instance ...

Utilize styled-components in next.js to import and resize .svg files seamlessly

I have been attempting to import .svg files into my next.js project, but I have not had any success. I tried importing the .svg files the same way as in my React project by creating a typing.d.ts file and importing the svg as a component. However, it did ...

In my conf.js file, I have included a total of 4 test cases within the spec[] array. My task is to execute 2 specific test cases from this list without deleting any of the existing

In my application, there are a total of 4 test cases and I need to run 2 of them without deleting any files from conf.js. Below is the content of conf.js: framework: 'jasmine', seleniumAddress: 'http://localhost:4444/wd/hub', // spec ...

Ways to redirect to a different page within a website

Today marks the beginning of my journey into Selenium automation with Python. I am embarking on a project to create a program that automates the process of purchasing items from a website. My goal is to continuously enhance the functionality of this bot in ...

Customize time formatting in Angular to accommodate localized time formats

I am utilizing Angular's localization service version 8.3.28 to support English, Spanish (Mexico) with code es-MX, and Spanish (Spain) with code es-SP While using the date pipe: {{ foo.Date | date: 'shortDate' }} The dates are changing to ...

How to automate the process of extracting and unzipping an always updatable Zip file from a website using Selenium, and then retrieving specific files from

I have been using Python with Selenium to download a zip file daily, but I am currently encountering some issues after downloading it to my local folder. Is it possible to use Python to dynamically read these files? For example, if the date in the file ...

The scrolling speed of the mousewheel in Firefox is notably slower compared to that of Google Chrome

Kindly review this sample link: When I test the above example in Chrome and scroll using the mouse wheel, the page moves up by 100px each time. The Y position is displayed as well. However, if I try the same page in Firefox 26.0 and scroll with the mouse ...