I am unable to retrieve any text from the class as it is returning a null value

Can someone please assist me with two issues I am facing:

1) Firstly, I am trying to match the text of an alert pop-up using the following code:

<div class="noty_message message"><span class="noty_text">Uh oh! Email or password is incorrect</span></div>

My current code is as follows:

var loginAlert = element(by.className('noty_text'));
expect(loginAlert.getAttribute('text')).toEqual("Uh oh! Email or password is incorrect")

However, I keep getting an error message saying: Expected null to equal 'Uh oh! Email or password is incorrect'.

Initially, I also attempted to find the text using getText()

2) The second issue involves a missing space in the text, but I am unsure how to fix it correctly. Here is the example:

 <span class="tooltip-text">Uh oh! This<br>isn’t an email</span>

My code for solving this problem looks like this:

var newInvalidEmail =  invalidEmail.getText().then(function (text) {
        expect(text.replace(/\n/, '')).toBe("Uh oh! This isn't an email");
    });
    expect(newInvalidEmail).toEqual("Uh oh! This isn't an email")

The error message received is: Expected 'Uh oh! Thisisn’t an email' to be 'Uh oh! This isn't an email'.

Answer №1

01- To retrieve the text content, you can use either getText() or getAttribute("innerText"). Be sure that there is only one element with the class name noty_text, and if it's not working, consider adding a wait before searching for the element.

var loginAlert = element(by.className('noty_text'));
expect(loginAlert.getText()).toEqual("Uh oh! Email or password is incorrect")

2- When using the replace function, insert a space as the second parameter instead of an empty string (replace(/\n/, ' ')).

var newInvalidEmail =  invalidEmail.getText().then(function (text) {
        expect(text.replace(/\n/, ' ')).toBe("Uh oh! This isn't an email");
    });
    expect(newInvalidEmail).toEqual("Uh oh! This isn't an email")

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

Getting around CORS using PHP and JavaScript/Ajax

I've been grappling with this issue for hours, but my lack of expertise in web development has me stumped. Here's what I'm struggling with: There is another website that uses a script to fetch information like this: var url = "numbers. ...

Tips on obtaining a byte array from within a JSON object

I am currently facing a challenge in retrieving a PDF file from the server, which is enclosed within a JSON object. When I send a byte array of the PDF to the front-end, I can successfully read it by configuring the responseType to arraybuffer. Subsequent ...

Soft keyboard on mobile fails to update when arrows are used in Ajax-populated dropdown menus

I am working on a web form that includes two select fields: Country and City: <select id="country" onchange="getCity(this);"> <option value="">-- Please select your country --</option> <option value="1">Austria& ...

Error encountered with es6 map in reactjs: Unexpected token

What could be causing the error "unexpected token ." in my JSX code that involves an array called breadcrumb = ['food','hotdog']? {breadcrumb.map(obj => { {obj} })} ...

Whenever I initiate a React project by running npm start, I encounter specific messages displayed on the terminal

After executing npm start to initialize a react project, I encounter the following error messages in the terminal: npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /Users/eraldomaia/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no such fil ...

Issues with React's onSelect event functionality are persisting

Is there an event handler in React for the onSelect statement? For example, when a user highlights some text within a paragraph using their mouse, is there a way to trigger an event that extracts the highlighted text? import React, { Component } from &apo ...

Trigger an alert in the view upon receiving an HTTP post request in the action of a controller from an Android client using the Phalcon MVC framework

Working within an MVC framework, I recently encountered a challenge. The scenario is as follows: I have an android client that sends an http post to the url "myweb/index/saveData" (where saveData is an action in the index controller). Although I am able t ...

Having difficulty organizing JavaScript Chart.JS charts into two rows, instead of having everything piled up in a single column

As I delve into JavaScript and Chart.JS for data visualization, I encountered a challenge with the layout. Despite resizing the charts in my template (linked below), all the charts are still displaying in a single column format. My goal is to have two rows ...

Floating Elements Centralized

I have a relatively straightforward HTML layout with a heading div at the top, followed by a Main div that contains a NavBar on the left side and a ContentDiv on the right. The issue I'm facing is that I can't seem to get my NavBar and ContentDi ...

Triggering a success message when clicked using JavaScript

<div id="success"> <button class="btn btn-primary btn-xl" type="submit" id="btnShow">Send</button> </div> As a beginner in JavaScript, I am struggling to write the code for displaying a success alert upon clicking the button. ...

Encountering an Error in Node.js When Defining Routes Using Variable Routes

Here is the code snippet from my App.js file- var routes = require('./routes'); app.get('/', routes.index); //var abt = require('./routes/about'); app.get('/about', routes.about); This is the code from my index.j ...

Reading a JSON file using Javascript (JQuery)

Struggling to figure out how to handle a JSON file using JavaScript. Here are the details : { "streetCity": { "132":"Abergement-Clemenciat", "133":"Abergement-de-Varey", "134":"Amareins" } } I am attempting to access ...

Getting access to the DOM element in AngularJS can be achieved through various methods

I'm a newcomer to AngularJS and I have successfully set up basic routing in my app. However, I am now looking to enhance the interactivity of my home screen by incorporating a typewriter js script: const texts = ['123', '456', &ap ...

Show a row of pictures with overflow capabilities

I am looking to develop my own image viewer that surpasses the capabilities of Windows. My goal is to design an HTML page featuring all my images laid out horizontally to maximize screen space. I also want the images to adjust in size and alignment as I z ...

Pass a parameter to an Angular class

I am encountering difficulties in inputting a value into an element with a ng-class Attempted the following code snippet: driver.FindElement(By.Id("limit")).SendKeys("10.00"); without success. I also tried - driver.FindElement(By.Id("limit_display")).Sen ...

Soundcloud's HTML5 Widget occasionally halts loading unexpectedly

Currently, I am building a website that features the Soundcloud HTML5 widget. However, I have encountered an issue where the widget does not load properly. Initially, everything was functioning well, but after numerous page refreshes during development, th ...

Tips for adjusting the ion-select popup height in Ionic

I've been attempting to customize the max-height property of a div that organizes elements in a popup using the interfaceOptions attribute in Ionic, but so far I haven't been successful. Here's what I have tried: cu ...

Searching for a new HTML document within existing HTML code using Python (specifically with Selenium)

Looking to gather details about a book on Amazon has been a smooth process for me, up until I reached the point where I needed to extract the content description. The content description is located within an iframe-container that initiates a new HTML code. ...

What are some solutions to troubleshoot the issue with my select dropdown menu?

I'm having an issue with my football team members array. I've categorized the players by position, and when I select a specific position (e.g., striker), only those players are displayed. However, when I press the 'secin' option again, ...

Injecting custom page headers based on the Angular 2 environment

Help! I'm trying to incorporate Google Tag Manager into my Angular2 app, but I'm struggling to figure out how to inject the necessary GTM script with different container IDs for development and production. I have two containers set up in GTM. Is ...