Tips for selecting multiple elements with the same class name in Protractor for Angular:1. Use the `element

Snippet of HTML code:

<div class="block ng-scope" ng-repeat="skills in data.primary_skills">
                    <div class="block skillsLineItem" ng-class="{manditorySkillsLineItem:skills.mandatory, skillsLineItem:!skills.mandatory}"> 

 <label title="Testing" class="skill-name col-xs-5 text-overflow-ellipsis ng-binding" ng-click="toggleMandatory(skills)">
                              <!-- ngIf: skills.mandatory -->
                              <!-- ngIf: skills.userdefined -->
                              &nbsp;Testing
                            </label>

Another snippet of HTML code

<label title="Test Scripts" class="skill-name col-xs-5 text-overflow-ellipsis ng-binding" ng-click="toggleMandatory(skills)">
                          <!-- ngIf: skills.mandatory -->
                          <!-- ngIf: skills.userdefined -->
                          &nbsp;Test Scripts
                        </label>

I am facing an issue with clicking on multiple elements with the same class name and ng-click values in our application. I need to click on both elements, so any assistance in achieving this would be greatly appreciated.

Answer №1

If you want to access and manipulate all elements, you can utilize the each() method:

element.all(by.css("label[ng-click*=toggleMandatory]")).each(function (label) {
    label.click();
});

To specifically target certain elements, you can employ the filter() function:

element.all(by.css("label[ng-click*=toggleMandatory]")).filter(function (label, index) {
    return index <= 5;
}).each(function (label) {
    label.click();
});

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 steps can I take to resolve a dependency update causing issues in my code?

My program stopped working after updating one of the dependencies and kept throwing the same error. Usually, when I run 'ng serve' in my project everything works fine, but after updating Chartist, I encountered this error: An unhandled exception ...

Reveal the class to the global scope in TypeScript

ClassExample.ts: export class ClassExample{ constructor(){} } index.html: <script src="ClassExample.js"></<script> // compiled to es5 <script> var classExample = new ClassExample(); //ClassExample is not defined < ...

What could be causing the malfunction in my 'sort' function? I have thoroughly checked for errors but I am unable to locate any

Exploring the world of JavaScript objects to enhance my understanding of functions and object manipulation. I have created a program that constructs an Array of Objects, each representing a person's 'firstName', 'middleName', and & ...

Maintain the chosen month in every dropdown toggle div in angular 4

While displaying data using toggle options, I am facing an issue where if I click on a different month, all other greyed out headers are displaying the previously selected values. I am trying to figure out a way to keep the value under Selected month as i ...

Setting a list as a value in a dataframe - a step-by-step guide

My goal is to populate cells in a table with the monthly activity data of GitHub users, organized by years and months (e.g., 2021_01, 2022_10). https://i.stack.imgur.com/BGwfx.jpg The Xpath for this information can be found here: //*[@id="js-contrib ...

Tips for leveraging stage 3 functionalities in TypeScript?

Array.prototype.at() is currently in the proposal stage 3. Even after adding "lib": ["ESNext"] to my tsconfig.json, I encountered the error: Property 'at' does not exist on type 'number[]'. Could you shed some light ...

Issue with specific route causing server to throw 500 error

Recently, I have been working on a small school project that involves creating our own API and connecting it to an Angular front end. While following some tutorials, I encountered an issue where my application started throwing internal server error 500 af ...

Issue with Vue.js: Nested field array is triggering refresh with inaccurate information

I've been working on a Vue page where I want to have nested field collections, with a parent form and repeatable child forms. Everything seems to be working fine except that when I try to delete one of the child forms, the template starts rendering i ...

Ran into a glitch while executing the command: Uh-oh! Something went wrong when initializing the App

Issue: When my app launches, it crashes before the ScrollTo() command is executed. Error message displayed on Appium: 'Encountered internal error running command: Error: Error occurred while starting App. Original error: com.disney.wdpro.androi ...

Received TypeError: Unable to call reset function - issue clearing input field post ajax request

Having Trouble Clearing Input Fields After AJAX Request: $.ajax({ type: "POST", url: "river_flow.php", data: { username: $("#username").val(), idv:$("#idv").val(), comment: $("#comment").val()}, cache: false, success: function(da ...

The Google Maps application is experiencing an issue with rendering maps

Here is my code without the google map key. I am not receiving any errors, but the map is not showing up. What could I be missing? To test it out yourself, you will need to add your own map key which you can obtain from here. <!DOCTYPE html> <h ...

Utilizing ng-class for dynamic routing and controlling

I am currently in the process of developing a dynamic framework using AngularJS. My plan involves allowing users to add new templateUrl and controller from a JSON file, like the one shown in templates.json: { "pages" : [ { "name" : "home" ...

Tips for eliminating Google pop-ups during testing and navigating on Google URLs

Whenever I use Selenium to navigate to Google, I always come across this annoying popup that prevents me from clicking on the search bar. Does anyone know of a way to get rid of this popup permanently without using any JavaScript alert methods? I've ...

What is the best way to ensure PyScript is completely initialized, including the environment?

Hey there! I'm hoping to catch a specific message being logged in my browser's console by a script I added to my HTML file, and then trigger a JavaScript action based on that. For instance, when "ABCD:READY" appears in the console, I want to cal ...

In Python, one way to incorporate an external function into a class is by calling it within the class and then returning to

Just wanted to clarify that I am currently working on implementing data-driven tests on a website using selenium. Here is the main code snippet: from a_folder.abc_file import userJourney from a_folder.a1_file import contact @ddt class testScenario(unit ...

Converting a json array into a map with the help of Underscore.js

My challenge involves parsing a JSON array into a map object, with the key being the state and the value being an array of objects that share the same state. An example JSON data set is provided below: { "totalRec": 10, "content": [ { "name" ...

What could be the reason for the defaultCommandTimeout not functioning as expected in my script

Is there a way to wait for only one particular element in Cypress without having to add wait commands everywhere in the test framework? I've come across the solution of adding defaultCommandTimeout in the cypress.json file, but I don't want it t ...

What is the best way to delay until text is visible within an element?

Could I potentially delay action until the appearance of an element, as indicated by the text within the STRONG section below? The content in question consistently changes based on specific triggers. <div class="alert message alert-success alert-da ...

Performing automated testing on URLs saved in a text file

I am trying to iterate through a text file that contains URL links, but I am facing an issue where the browser opens each API link one after another and closes them before completing the test successfully. Is there a solution to this problem? Here is my c ...

Issues arise when the Slick functionality fails to load following an ajax request

I've come across a situation similar to the one on this post. I'm having trouble getting my slick carousel to work after a successful ajax call. Despite trying all the solutions provided, it's still not functioning as expected. The code for ...