Select an element in Protractor with a matching class that contains specific text and then exit

In my Protractor testing, I have been successful in locating text using element.all(by.repeater()) and iterating through each to find a match. However, the issue arises when trying to exit the iteration once a match is found and clicking on the matched element.

I attempted to use .each(), but unfortunately, I am unable to break out of the loop once the match is identified.

Do you have any suggestions or solutions for this problem?

Answer №1

Using each() in this scenario may not be the best approach. Consider using filtering instead, like demonstrated below:

element.all(by.repeater("test in tests")).filter(function (elm) {
    return elm.getText().then(function (text) {
        return text === "Desired text";
    });
}).then(function(filteredElements) {
    filteredElements[0].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

The Google Maps API functions flawlessly on Chrome and Firefox, however, Internet Explorer seems to be having trouble running it

When using the Google Maps API, everything works fine on Chrome and Firefox but Internet Explorer encounters an issue. I am loading the API with jQuery and calling initialize(); The error message in IE6 states: error 'google' undefined function ...

The background property does not support linear-gradient in CSS

I am currently working on creating a tree structure using the vue-orgchart library (link) Everything is functioning correctly, but I am interested in changing the green background color of the node (ignoring the white portion). https://i.sstatic.net/EEcd ...

What is the correct way to use setInterval in a React component's constructor?

I'm trying to set an interval when the main component renders. I attempted to do this in the constructor like so: constructor(props) { super(props); this.props.fetchUserInfo(); this.props.fetchProducts(); setInterval(console.log(&a ...

Vue JS: Easily Calculate the Total Sum of All Columns

An example of a query in the backend controller public function show($id) { $structural = DB::table('attendance')->where('payroll_daily_id',$id) ->where('assignment','STRUCTURAL') -&g ...

Struggling to locate the element with Python and Selenium?

Hi there, I'm just getting started with Python and Selenium, and I'm having trouble targeting an element on a login website. I've tried several methods like class name, css selector, id, and name but nothing seems to work. However, when I ma ...

Error: Trying to access 'whenReady' property of undefined variable is not allowed

As a beginner in electron app development, I am facing an issue when running npm start from the terminal. The error message I receive is: TypeError: Cannot read properties of undefined (reading 'whenReady')... This specific problem seems to be ...

An issue arose in nodejs when attempting to use redirect, resulting in the error: "Error [ERR_HTTP_HEADERS_SENT]: Unable to modify headers after they have

I am currently working on a project where I encountered an unexpected error. My goal was to redirect the server to specific routes based on certain conditions, but I am facing difficulties. routes.post("/check", (req, res) => { console.log(& ...

Traverse through a list utilizing a jQuery carousel animation

I am attempting to create a looped list with a carousel effect. It seems like the script should first determine the total number of items in the list in order to perform calculations. Then, it can execute an action such as this: Adding an item on one sid ...

Ways to resolve the issue of data not displaying on the page, even though it appears in the

I am attempting to upload an image that has been converted to a URL using Ajax. The issue I am facing is that $image = $_POST['imgData']; does not display anything, but when I check the developer tools in the network preview, the data can be seen ...

Why does my function only execute once? I am attempting to run the function multiple times, but it seems to only run once before the previous invocation is completed

Currently, I'm in the process of working on a book that utilizes a page turn effect in jQuery without the use of any plugins. The implementation of the page turn effect works smoothly when navigating through pages one by one. However, my goal now is t ...

Comparison between PageObject gem's management of nested tables and iframes

I am currently utilizing the PageObject gems for testing Salesforce, which contains numerous nested tables. I'm curious if anyone has found a unique approach to accessing cells within these nested tables (as shown in the example below). Specifically, ...

Unable to retrieve the text from a input field that is marked as read-only

I'm currently developing a script for web automation that needs to retrieve text displayed after a button click. The challenge is that the text is enclosed within an input element, like this: <input type="TEXT" autocomplete="off" ...

Tips for transferring information from a parent to a child controller in Angular using the $broadcast method?

I am trying to send an id argument to a child controller using Angular's $broadcast method, but despite my best efforts with the code below, I can't seem to make it work. Any suggestions on what might be incorrect in my implementation? ParentCtr ...

Puppeteer: Interacting with login dialog box fields

I am currently facing an issue while attempting to generate a .pdf file from a specific page on our Intranet using Puppeteer and Headless Chrome within Node.js. Generating a .pdf file from a regular webpage poses no challenge, but I am encountering diffic ...

Having difficulties in traversing through the response body and performing manipulation/filtering of the response object with node JS

In the following code snippet, I am calling a REST endpoint and receiving a response back. When I tried to log the response.body in the console, it worked perfectly. var express = require('express'); var app = express(); var PORT = 8001; var ...

Issue with retrieving the positions of two numbers in an array

I encountered a challenge: I have an array of integers nums and an integer target. My goal is to find the indices of two numbers in the array that add up to the specified target. Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Output: Thi ...

A demonstration using selenium - issue encountered: unable to terminate the process

I am brand new to using Selenium with Java. I followed an online tutorial and tried running a simple program to check if a webpage is successfully opened. I'm confused as to why these error messages are appearing, especially since I copied and pasted ...

Multi-threaded Locking Technology

Greetings everyone, I hope you're doing well. Currently, I am working on a project where each process(thread) will be responsible for reading from either multiple txt files or one big text file with a specific portion assigned to it. For instance: Le ...

Customizing the design of vuetify table header to your liking

My goal is to implement a custom style for v-data table headers using the fixHeader method. The CSS code is intended to keep the header fixed in place even when scrolling horizontally. The issue arises as the style is applied to the inner <span> ele ...

Is there a similar alternative to {useLocation} provided by 'react-router-dom' that can be used in Next.js?

import { useLocation } from 'react-router-dom'; Currently utilizing Nextjs, I'm seeking assistance in finding an alternative for useLocation ` import Link from 'next/link'; import { FC } from 'react'; import {useRout ...