Retrieving the text of a button using Protractor

After developing a unique locator to identify an element utilizing the ng-click method, I was able to retrieve a button reference from my Document Object Model (DOM).

this.button = element(by.ngClick('login()'));

Now, my goal is to extract the text displayed on the button using the aforementioned reference. If the button contains text like "Click to Login," how can I obtain this text from the button reference?

Answer №1

To retrieve the text of an element selector, you can utilize the getText() method. However, it's important to note that this method returns a promise. To handle this promise in Protractor tests, you can pass it to the expect function for comparison like so:

expect(this.label.getText()).toBe('Welcome Message');

If you require the retrieved text for other purposes within your code, you will need to manually resolve the promise as shown below:

this.label.getText().then(function (text) {
    console.log(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

Refreshing the webpage causes a change in the displayed HTML content

Upon the initial load of the HTML, the text will show as "Yes". However, upon reloading or when loading from the cache for the second time, it should display a different text, "NO". ...

What is the best way to adjust the scroll speed within a specific element using React?

Hey there, I'm currently working on adjusting the scroll animation of a div (MUI Container) to make it smoother and slower. I've spent some time searching online for a solution but haven't found anything helpful so far... By the way, I' ...

Troubleshooting issue: EJS loop not functioning correctly when handling JSON information

Having an issue with looping in an EJS file. Here's the data I'm working with: { "name": "Marina Silva", "info": [{ "periodBegins": "Sun Apr 14 23:48:36 +0000 2011", "periodFinishes": "Sun Apr 7 23:48:36 +0000 201 ...

Breaking apart values separated by semicolons in JavaScript to create separate rows with additional information

Here is the provided data: result = [ { "Id":"0012v00002InPVmAAN", "Test__c":"India; Africa; Mombasa", "Test1__c":"AFR; TFR; GFR" } ] I want to convert the above data into a CSV file by splitting t ...

How can Ext JS 4 handle the transmission of multiple metaData to support multiple dynamic grids by utilizing a single JSON file?

Looking to create multiple grids on a single panel using an accordion layout? I'll be dynamically generating all the grids based on metaData in JSON and handling metachange listener events on my store to reconfigure the grid. But here's the quest ...

Using VueLoaderPlugin() results in an 'undefined error for 'findIndex' function

Currently, I am in the process of integrating a Vue CLI app into another web project that we are actively developing. The Vue app functions without any issues when utilizing the development server bundled with Vue CLI. Due to the presence of .vue files wi ...

How to handle event methods with Vue

Currently, I am facing a challenge in passing an event downward with a bound change listener to a child input component. Although I am utilizing wrapped input components, my goal is to define methods within the parent component. //App.js: <currency-inp ...

Injecting attributes from a form into partial components

I have been working on a NodeJS app and have successfully implemented handlebars and partials so far. Currently, I am at a stage where I need to create both 'view' and 'edit' forms for a car. For instance, once the user submits an appl ...

Looking for a character that includes both lowercase and uppercase letters

Here is the JSON data I have: [ {"lastName":"Noyce","gender":"Male","patientID":19389,"firstName":"Scott","age":"53Y,"}, {"lastName":"noyce724","gender":"Male","patientID":24607,"firstName":"rita","age":"0Y,"} ] var searchBarInput = TextInput.value; var ...

Retrieve data from a JSON gist by parsing it as a query string

I have a JavaScript-based application with three key files: index.html app.js input.json The app.js file references input.json multiple times to populate content in div elements within index.html. My goal is to enhance the functionality so that when acc ...

Redux Dilemma: Stagnant Data in Redux Repository

Struggling to pass data fetched through axios into the Redux store for use in another component. While other actions and reducers are functioning correctly, this one seems to be causing issues. Here is the flow of data: Begin in the Filter component comp ...

Progress bar for uploading files

Similar Question: Upload Progress Bar in PHP Looking for suggestions on a simple and effective method to implement a file upload progress bar. Interested in a solution that involves both javascript and php. Any recommendations? ...

Having trouble with Lerna bootstrap? You might be running into the dreaded npm error code E401

Every time I run Lerna bootstrap on Jenkins, it fails with an error, but it works fine on my local machine. npm ERR! code E401 npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager" Package.json in the main folder ...

Using AOS in WordPress causes the specified elements to appear as blank rather than fading in

Struggling to integrate Michalsnik's Animate On Scroll plugin into my Wordpress site. Followed the instructions to add the "data-aos" attribute to a div, but the element ends up being blank instead of fading in. <div class="textbox center branch-b ...

How can I utilize the Camera function in Cordova?

I am in the process of developing a Cordova app that will be compatible with both iOS and Android platforms. One of the key features of the app is the ability to display a camera within a specified frame. Below the camera frame, there will be a button labe ...

When sending a request from Vue.js using Axios to PHP, the issue arises that the .value property is

There is a chat box with bb smileys underneath. Clicking on the smileys adds them to the text in the input box. However, when using axios to post, the array is empty. Manually entering the smiley bbcode works fine. <input id="txtName" @keyup.enter="ad ...

Leveraging grunt-develop

I have recently developed a basic NodeJS + Express application that runs smoothly when I use the command node app.js. However, my current task is to incorporate grunt-develop into my project. Here is how I configured it: grunt.initConfig({ develop: { ...

Guide to emphasize the active navigation tab in a particular scenario

Utilizing this template for JavaScript to choose the appropriate navigation using JQuery, with reference to this API. Snippet of my current code: index.php <html> <head> <title>ChillSpot Alpha 1.2.3</title> &l ...

Exploring the Power of Promise-Tracker in AngularJS

Having trouble with promise-tracker implementation. I am trying to track a conversation using the code below: JS: angular.module('myModule', ['ajoslin.promise-tracker']) .factory('Conversation', function (promiseTracker) ...

Is it possible to retrieve local variable JSON arrays using ajax/getJson()?

When starting a project without a database or data source, I often create json arrays in a *.js file to populate screens until the data modeling or database creation is complete. I am trying to figure out how to write an ajax/getJson() function to access ...