Find the element in Protractor by using multiline text detection

I am facing a challenge with locating certain webElements on the page based on specific text conditions. The elements return the following text when converted:

School, Primary School\n' +
Church, Catholic Church,

FireStation, Primary Station\n' +
Church, Catholic Church,

School, Primary School\n' +
FireStation, Primary Station,

My goal is to identify and locate the first element from the list which contains:

School, Primary School\n' +
Church, Catholic Church,

I have attempted to locate them using 2 separate conditions but chaining seems to be ineffective.

element(by.cssContainingText('.given_class',`${interpolation[for_school]}`, `${interpolation[for_church]}`)).getText()

Unfortunately, this approach did not provide the desired outcome. I also tried chaining locators without success:

element(by.cssContainingText('.given_class',`${interpolation[for_school]}`)).element(by......`)).getText()

Despite trying various methods, I have been unable to successfully locate these elements on the page. Each element shares similar attributes such as class, id, and type, making it essential to find them specifically by text content.

Answer №1

utilize the xpath and operator

element(by.xpath('//*[contains(text(),"find element") and contains(text(),"within multiple lines of text")]'))

experiment with this method on a different web page to identify question headers using

//*[contains(text(),"locate element") and contains(text(),"from multiline text")]

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

Ways to customize weekend colors in v-calendar (distinct colors for Saturdays and Sundays)

Looking to customize the appearance of weekends in your calendar by changing their colors? I have a component for the v-calendar that can help with that. Here's the code: <div id='app'> <v-date-picker title-position="left&quo ...

How to Identify onmouseout in Google Gadget without an event attribute within HTML

I am in need of a JavaScript method that can identify when the mouse exits an element with the id="myDiv" within an if() clause. Unfortunately, I am unable to utilize the JS onmouseout event directly in my HTML. It is essential for me to be able ...

Unable to determine the reason why the JavaScript plugin is not functioning as expected

I have been attempting to set up a JS modal window and have essentially copied the code for the plugin exactly as instructed, but it is not functioning properly. Here is my code... <!doctype html> <html> <head> <meta charset="utf- ...

React Native: Unexpected Challenge in State Updates

Below is the code I am currently using: makeRemoteRequest = () => { let items = []; models.forEach(element => { //models contains an array of different models this.pushReports(element, items); }); console.log("The item ar ...

Can 3D objects be easily moved by dragging and dropping in sap ui5?

Can a 3D object be generated in SAP UI5 allowing for interactive movement of objects? For example, creating a 3D model of a house where individual pieces like chairs can be manipulated. Is there a method to accomplish this task effectively? ...

ERROR: Expo TaskManager Notifications [TypeError: Attempting to call an undefined function (near '...Notifications.presentLocalNotificationAsync...')]

I'm currently trying to figure out how to send notifications whenever a task is triggered, but I keep encountering an error that I can't seem to fix. Here's the error message: TaskManager: Task "background-fetch" failed:, [TypeError: unde ...

Extract information from a JSON string stored in a variable and transform it into objects within the $scope.variable

I currently have a string variable that contains JSON data displayed below. var jsonstring = [{"latitude":"51.5263","longitude":"-0.120285","altitude":"","device":"123","rating":"5","region":"Europe","customer":"","time":"1-2 Weeks","error":"Error 1","app ...

Jsx Component fails to display following conditional evaluations

One issue I am facing is having two separate redux stores: items (Items Store) quotationItems (Quote Items). Whenever a product item is added to quotationItems, I want to display <RedButton title="Remove" />. If the quotationItems store i ...

The 'errorReason' property is not found within the 'MessageWithMdEnforced' type

I am currently working on a project using meteor, react, and typescript. Here is the section of code that is causing an error: {message?.errorReason && <div>{message?.errorReason}</div> } The error message I am encountering is: "P ...

How can states be passed down as props in React?

This might be a beginner question, but I've been struggling with it all day. Any help would be appreciated. Apologies for the length, I just wanted to explain everything I'm having trouble with I am attempting to create custom buttons by build ...

Combining JQuery Validation with JSF for Seamless Form Submission and Page Refresh

After successfully integrating JQuery Validation script with my JSF 2 page, everything seems to be working fine until I try to submit the form. Despite finding similar answers here and here, the issue still persists: the page refreshes and the bean is not ...

Struggling with the proper state updating in React hooks when using dynamic naming conventions?

I am currently working with a react component that handles login requests to my server. This component is housed within a modal using Material UI. <TextField onChange={handleChange} autoFocus name="email" ...

What is the most effective method for handling extremely large Long numbers in Ajax?

When it comes to Javascript, all numbers are represented as double-precision floating-point. This can result in a loss of precision when handling numbers that exceed the 64 bit Java Long datatype limit of 17 digits. For instance, a number like: 7143412520 ...

marking locations on Google Maps with pins

Is there a simpler method to pinpoint multiple locations on a Google map? I have numerous coordinates to mark, and the current process is quite challenging. The current method involves using the following controller: .controller('MapCtrl', func ...

Using express version 4.x to send an empty JSON object

I'm struggling with returning an object in JSON format using Express. What's confusing me is the following code snippet: class Greeting { Greeting(name) { this.name = name; } get name() { return name; } } app.get('/json/:na ...

Issue: Unable to change onclick event using JavaScript I am facing a

Presently, I have this code snippet: function tp_visible(action){ if(action==1){ document.getElementById("tp").style.display='block'; document.getElementById("tp_action").onclick='tp_visible(0); return false;&apo ...

Avoid reloading the page in PHP when the browser back button is clicked

I've built an HTML form where the values are passed to a second page using POST method. On the second page, I have an edit button that, when clicked, redirects back to the HTML form page with the user's typed values. However, my dilemma is figuri ...

Is there a way to reset back to the default CSS styles?

I have a div container with a nested span element (simplified). <div class="divDash"> <span>XX</span> </div> The CSS styling for the div makes the span initially hidden and only visible when hovering over the parent div. .div ...

Issue encountered when initializing Selenium WebDriver due to NoElementException

Here is the code snippet I'm working with: package pageobjects; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.safari.SafariDriver; public class MainPage { ...

Extract latitude and longitude data using Mapbox's autocomplete feature

Currently, I have integrated Mapbox with autocomplete in a Vue component: <template> <div> <div id='geocoder'></div> </div> </template> <script> import mapboxgl from 'mapbox-gl& ...