What is the best way to distinguish between enabled buttons using Protractor?

I am facing a challenge with a table containing 20 buttons. Half of these buttons are disabled while the other half is enabled. I am looking for a way to filter out the enabled buttons and click on each of them using a for loop. The buttons that I want to click have the class "fa fa-check". However, I am struggling with filtering out the disabled buttons.

The disabled buttons have an attribute called 'disabled' with the value 'disabled'. This is the key difference between the enabled and disabled buttons.

            for (var i = 0; i < numberOfRows; ++i) { //numberOfRows
                var button = element.all(by.repeater('tulemus in noue')).get(i);
                button.getAttribute('disabled').then(function(status) {
                    if (I am unsure how to verify the correct status) {
                          $$('.fa-check').get(i).click();
                          console.log('enabled element clicked');
                    } else {
                        console.log(status);
                        console.log('element is disabled');
                    }
                });
            }

Here is the HTML code for two buttons

Answer №1

If you want to loop through array elements in JavaScript without using a traditional for loop, you can utilize the each() function. Take a look at the example code snippet below:

   element.all(by.repeater('tulemus in noue')).each(function(button,index){
            button.getAttribute('disabled').then(function(status) {
                if(!status&&index=0){
                  button.click();//click if button is enabled
                 }
               else {
                    console.log(status);
                    console.log('element is disabled');
                }
            });
        });

Answer №2

Another way to accomplish this is by utilizing the filter() method:

element.all(by.repeater('result in list')).filter(function(item){
  return item.isEnabled().then(function(isEnabled){
       return isEnabled;
    })
 }).each(function(enabledItem){
       enabledItem.click();
 })

Answer №3

Try implementing the isEnable protractor function in your code to determine if a button is enabled or not. Here's how you can apply it:

var enabledButtons = element.all(by.repeater('tulemus in noue'))
.filter(button => { return button.isEnabled() });

This will give you an array of elements containing all the enabled buttons on the page. You can then work with these buttons or continue filtering them further. For instance, you can filter only the visible buttons like this:

var visibleButtons = enabledButtons.filter(button => { return button.isDisplayed() })); 

I hope this information proves useful for your implementation. Good luck!

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

Using MediaQuery from react-responsive to selectively hide individual JSX attributes

I have a button element that includes both the Profile Picture and the Info, which consists of the first name and last name. My goal is to hide only the profile picture (profileImageProps={profileImageAndBasicInfoProps.profileImageProps}) when the screen ...

Shorten Text - React Native

I currently have a React Native application with a FlatList component. The logic I initially implemented was to display an Expand/Collapse arrow whenever the content at the 100th position in the list is not empty. However, I now realize that this approach ...

What is the best way to implement onChange for multiple form fields in Reactjs?

Can anyone help me troubleshoot my form? I'm having issues with typing into the fields and nothing happens when I try. Initially, whatever text I input would show up in all the fields simultaneously, but after making some changes, it stopped working ...

Use JavaScript to swap out images

How can I change the image arrow when it is clicked? Currently, I have this code snippet: http://codepen.io/anon/pen/qEMLxq. However, when the image is clicked, it changes but does not hide. <a id="Boton1" class="button" onClick="showHide()" href="j ...

JavaScript function is returning 'undefined' instead of an integer

My JavaScript/jQuery function is not functioning correctly and instead of returning an integer, it returns undefined. function __getLastSelectedCategory(table_id) { if ( jQuery('.categories_table[data-table-id="1"]').find('td.active&apo ...

What is the best method for showcasing two images side by side in a column layout?

I need to showcase 2 images in a row using AngularJS, with the next two images in the following row and so forth. Img1 Img2 Img3 Img4 This is my code: <section id="content"> <div class="content-wrap"> <div class="container clearfix "& ...

The Ajax response fails to update my viewmodel

I have a value and a list that I need to update from within an Ajax callback. After retrieving a fresh value using .get(), I try to assign it to my view model's property, but the UI does not refresh properly. Below is the code snippet: function Searc ...

It seems that BeautifulSoup and Selenium are unable to locate the div or text elements on the website

I have been attempting to utilize BeautifulSoup or Selenium in order to retrieve the Head to Head text or its corresponding div element on betexplorer (link provided below), but my efforts have unfortunately proved to be unsuccessful. Despite being able to ...

Navigating with Link in React Router DOM v5 to successfully pass and catch data

In the process of developing a basic chat application, I encountered an issue with passing the username via the Link component. Below is the relevant code snippet: <Link to={{ pathname: `/${room}`, state: { the: user } }}> Enter room </Link> ...

`How can I utilize Python Selenium to enlarge an Angular custom element with shadow DOM?`

Even with 4 years of experience in Selenium, I encountered a problem that was new to me. It seems like only expert Python Selenium developers can tackle this issue. I attempted to use the following function to retrieve an Angular element, but unfortunate ...

Sending CSV files to users using MEANJS

Currently, I am employing the MEANJS framework to create a Node.js application. Essentially, I have JSON data stored in MongoDB and I am utilizing the json-csv NPM module to convert it into a CSV format. I managed to successfully download the CSV file loc ...

Trouble with React Material Select Options Failing to Populate

After iterating and producing MenuItems, I am able to see the items when I console.log, but in the UI, the dropdown appears empty. I'm puzzled as to why the Select's are not being populated. Any thoughts on this issue? Below is the supplied code ...

Adjust the start and end dates of the Bootstrap datepicker according to the chosen value

I am looking to dynamically set the startDate and endDate of a Bootstrap datepicker based on the value selected in an option form. For example, if I select "Boby" from the options, then the datepicker should be configured with startDate = 2016-10-04 and e ...

Interactive Navigation Bar in JavaScript

Is there a way to create a horizontal menu with an arrow that follows the mouse cursor? I saw this effect on a website (http://cartubank.ge) and I'm curious if anyone has the source code for it? Your help would be greatly appreciated. ...

Is the Date Epoch a reliable form of unique identification?

Currently, I'm developing a Node API and encountered a situation where I need to create a unique 15-digit random number for a model without using autoincrement. The challenge is to ensure that the generated number is not trivial. I am hesitant about ...

Using jQuery to efficiently handle dynamically added elements by combining the ".on" and ".each" methods

I am currently in the process of dynamically inserting new elements into my page, and these elements have a specific structure that is represented as follows: <div id="cars"> <input type="text" name="car_added[]" class="car" /> <inp ...

Error: The JS Exception has not been handled, as it is stating that 'undefined' is not an object when evaluating 'global.performance.now' in react-native-tvOS

I am currently working on a React-Native-tvOs app and despite following all the instructions from the react-native-tvOs GitHub page, I keep encountering an error when running the default template app. Even after running the script provided on the GitHub re ...

A method for increasing a counter using only an instance of a class or function without accessing its methods or properties in Javascript

Looking at the task ahead, let increment = new Increment(); I have been tasked with creating a Javascript class or function called Increment in order to achieve the following: console.log(`${increment}`) // should output 1 console.log(`${increment}`); ...

Using jQuery, retrieve the "select" element within a specific row of a

I am working on a table row that has the following HTML structure: When the user interacts with the "Name" field, I trigger the "select" event and pass it to the nameDropChanged function. Once I have a reference to this select element, I need to change th ...

Save the data in Redux and access it back

I am currently using material-ui-dropzone to upload an array of files and store them in redux However, when I try to retrieve the file from the redux state, it is not recognized as type "File" and appears differently in devtools https://i.stack.imgur.com ...