Utilize Protractor to extract the text within a specified span element

Is it possible to check if the text of the span within the button is "Vigente" using expect and Jasmine? If so, how can I achieve this?

<button _ngcontent-hke-28="" class="btn btn-success disabled" tabindex="-1">
<span _ngcontent-hke-28="" class="glyphicon glyphicon-check">
</span> Vigente</button>

Would xpath work in this way:

/html/body/application/auth-container/layout/div/main-content/div/norma-cadastro/div/form/div[8]/div/button/text(Vigente)

Answer №1

It seems that the XPath expression you're using is incorrect since the Vigente part inside the parenthesis is unnecessary. It's also advisable to avoid absolute XPath expressions as they may break if there are multiple levels in the path. Furthermore, the Protractor team does not recommend the use of XPaths.

Instead, consider locating the element by partial button text and verifying its presence:

expect(element(by.partialButtonText("Vigente")).isPresent()).toBe(true);

Alternatively, you can find the element by using a CSS selector and checking its text content:

expect($("button.btn-success").getText()).toContain(Vigente);

However, the CSS selector button.btn-success may be too general, so try to make it more specific if possible.

Answer №2

It's hard to say whether it is accurate or not.. However, you can verify it yourself in Chrome Dev tools. Just inspect the element and then right-click on the element in HTML and select Copy. I suggest using ID's or angular model if possible. XPaths tend to change as the HTML changes (unless you are using ID's in XPath), making test maintenance difficult.

Take a look at the image below for reference.

https://i.sstatic.net/dOSS4.png

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

Steps for combining two collections into a single output in MongoDB with Node.js

My MongoDB collections consist of data that I need to merge using the $lookup operation. However, the result I get contains a nested array structure that is not ideal. I am looking for a solution to format the result as shown below: First collection locati ...

Ways to conceal a badge using JavaScript

Can anyone help me figure out how to edit the data-count of a badge and hide the badge using JavaScript in a Bootstrap 5 navbar with a stacked Font Awesome icon? I have tried the following: document.getElementsByClassName("p1 fa-stack fa-2x has-badge ...

Component loader with dynamic rendering for multiple components

Currently, I am in search of a method to dynamically render components within my Angular application. While exploring various options, I came across the concept of dynamic component loading in Angular (refer to https://angular.io/guide/dynamic-component-lo ...

When a card is clicked in the parent component, data is sent to the child component in Angular. The card contains an image, name, ID,

How can I pass data from a parent component (nfts) to a child component (main) when a card is clicked? The card contains images, ids, names, and more information. I've attempted using @Input() but haven't been able to receive the value in the ch ...

Tips for setting a default value in a Multi Select component with reactjs and Material UI

Is it possible to set a default value on a Multiple selection (CHIP) using reactjs and material ui? Despite searching extensively online, I have not been able to find any relevant documentation addressing this issue. import * as React from 'react&apos ...

jQuery: Function is not running as expected

I'm facing a challenge in executing a function twice, and I'm having trouble identifying the issue. Check out my JSFiddle at the following link: http://jsfiddle.net/g6PLu/3/ Javascript function truncate() { $(this).addClass('closed&apo ...

Expandable List using AngularJS with ng-repeat and ng-show

I'm facing an issue with the ng-show index. What I need is to update the ng-show index dynamically in AngularJS. For instance: <div class="row" ng-repeat="list1 in Items track by index"> <button ng-click="vm.showLoc($index)"> ...

Refresh the webpage source code for an AJAX request

When using AJAX calls on a page, I have noticed that the page source remains unchanged. This can be problematic if a user performs forward/backward operations in their browser, as the browser will display the original HTML code instead of the updated conte ...

How can I remove the div container every time the submit button is clicked?

I am currently working on a form that is capturing values as shown below. <form role="form" id="calculate"> <div class="form-group"> <select class="form-control" id="paper"> < ...

Refreshing PHP Script

I have a PHP file that contains a combination of HTML elements, JavaScript functions, and PHP scripts. I need to rerun a specific part of the PHP script repeatedly. Let's consider the following example: <html> <?php $connection = ...

Error: 'require is not defined' pops up while trying to import into App.js for a React App built with CDN links

My latest project involves a React App that showcases an h1 tag saying "Hello World" on the browser. Rather than utilizing npm, I have opted for CDN links to set up the application. The structure of the App consists of three key files: An index.html file ...

The complete page gets re-rendered when Nuxt child routes are used

When I attempt to utilize child routes, my goal is to maintain specific data on the page while modifying other content. To illustrate this concept, I have created a straightforward example available at this link. After selecting "cat" and increasing the ...

How to update a value within a deeply nested array in MongoDB and then sort the data

In my document, I have a list of timestamps that are sorted by time: { _id: '1', timestamps: [ { id: '589b32cf-28b3-4a25-8fd1-5e4f86682199', time: '2022-04-13T19:00:00.122Z' }, { id: '781 ...

What is the functionality of an Angular service that retrieves an

It appears that Angularjs services are constructed by passing in a Contructor function: app.service('serviceName', function(){ this.var1 = 'foo'; this.method1 = function(){ } }); Angular executes this function using the new ...

Ways to integrate a component within a custom component in the React framework

I am looking to dynamically change the body content, how can I achieve this? import React from 'react' // import { Link } from 'react-router-dom' export default function ProjectTemplate(props) { const Css= { "--backgr ...

Speaking about the `this` Vue component in an event listener context

Consider this Vue component that is equipped with a global event listener: let myApp = new Vue({ data: { foo: 0; }, methods: { handle: function(event) { this.foo = 1; // 'this' pertains to the handler, not ...

Unlock the Power of TWBS Ratchet: Manually Closing Modal Windows

Currently, I am in the process of developing a mobile web application using Ratchet. The main task at hand involves opening a modal, filling out a form, clicking a button to save the input data, and then closing the modal. Although I have managed to close ...

When using JavaScript to redirect with window.location, the referrer header is not properly set

Currently, I am attempting to utilize window.location in React to redirect to a third-party page. However, upon making the redirect, the third-party server is not receiving a referrer header from my redirection. Any assistance on resolving this issue wou ...

Tips for customizing fonts in a WordPress object

WordPress is sending me an object that I need to work with. The main issue at hand: the font styles of WordPress posts in my app are all inconsistent. How can I go about styling these fonts uniformly? Take a look at this Plunkr if you'd like to expe ...

Different ways to utilize ng-repeat with option tags

Hello, I am currently utilizing a dropdown feature that fetches options from a database. To do this, I have created an array as shown below: const myArray = new Array(); myArray = [{className:5,avg:40},{className:6,avg:50},{className:7,avg:40}}]; Within ...