Tips on selecting an element with matching element attributes on a button that contains a span tag using Protractor in TypeScript

https://i.sstatic.net/LAhi8.jpg

Seeking assistance with creating a protractor TypeScript code to click a button with _ngcontent and span class. Does anyone have any suggestions on how to achieve this? Here is the code snippet from the site:

<form _ngcontent-c34 novalidate class="ng-untouched ng-unreal ng-valid">
    <atx-create-license-act-main _ngcontent-c34 _nghost-c36>
       <button _ngcontent-c36 color="accent" mat-raised-button class="mat-raised-button mat-accent">
           <span class="mat-button-wrapper">Add License</span>
           <div class="mat-button-droped mat-droped" matdrop></div>
           <div class="mat-button-focus-overlay"></div>
        </button>
    </atx-create-license-act-main>
</form>
<form _ngcontent-c34 novalidate class="ng-untouched ng-unreal ng-valid">
    <atx-create-license-act-main _ngcontent-c34 _nghost-c36>
       <button _ngcontent-c36 color="accent" mat-raised-button class="mat-raised-button mat-accent">
           <span class="mat-button-wrapper">Add License</span>
           <div class="mat-button-droped mat-droped" matdrop></div>
           <div class="mat-button-focus-overlay"></div>
        </button>
    </atx-create-license-act-main>
</form>

I've attempted the code snippets below but none seem to work...

clickdone = element.all(by.cssContainingText('.mat-button-wrapper','Add License')).get(0);
clickdone = element.all(by.css('button.mat-raised-button.mat-accent')).get(1);
clickdone = element(by.cssContainingText('span.mat-button-wrapper','Add License'));
clickdone = element.all(by.cssContainingText('button.mat-raised-button.mat-accent','Add License')).get(0);

Subsequently performed...

clickdone.click();

However, none of the above code snippets seemed to work and an error message states "Failed: element not interactable". What does this mean? I am currently stuck on this issue, does anyone have any suggestions on how to resolve it?

Answer №1

Here is an alternative suggestion:

addLicense = element.all(by.css('button>span.mat-button-wrapper');

browser.wait(protractor.ExpectedConditions.elementToBeClickable(addLicense.get(0)), 5000); 
addLicense.get(0).click();

Make sure to adjust the index according to the specific button you want to click.

I hope this solution proves useful for you.

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 <servicename> is inaccessible within an error function in Angular2

I encountered an unusual issue in angular2. While the code below is functioning correctly: loginResult.subscribe( (data) => this.response = data, (err) => this._ajaxService.handleError(err, 'A string to summarize th ...

Initiating the node js service locally

I have been working on a Node.js and Gradle application, but I'm having trouble figuring out how to run it locally. So far, I've done the Gradle build (./gradlew) and NPM run build (compile), with all my dependencies neatly stored in the node_mo ...

What is the process for converting language json files into different languages?

I'm currently using ngx-translate to localize an Angular app. With over 20 languages that need translation, I am in search of a tool that can efficiently translate the language json files. While I did come across a helpful website, it proved to be ti ...

What is the best way to employ the *ngIf directive in order to alter an image?

I'm in the process of developing an application using the following technologies. How can I implement the use of *ngIf directive to switch between two images? Here's a more detailed explanation: I have two images, one representing the male symbol ...

Using a modulus operator in Angular 6 to conditionally show elements

Trying to achieve a specific layout for an object in an array using ng-For and ng-If. Here is the desired recovery code, and here's what I've attempted so far in my code snippet enter image description here: <div class="recovery-code" *ngFor= ...

I am facing an issue with toastr in Angular 8 as it is not functioning properly and showing me errors

I encountered an issue while trying to use Angular 8 toastr. The error message in the console is as follows: ngx-toastr.js:264 Uncaught TypeError: Object(...) is not a function at ngx-toastr.js:264 at Module../node_modules/ngx-toastr/fesm5/ngx-toastr.js ( ...

Is it possible to control Firestore's data using an Angular service?

I am currently developing a basic example (Tour of Heroes) in Angular.io utilizing Firestore. In order to enhance readability and organization, the sections related to Firestore were segregated within the service and then referred in each component. Howev ...

How can we best store the component's state in the URL in AngularJS?

I am working with a reusable widget that has its own state. This state includes the content of the search bar (2), one or more select boxes (1), and the tree where the user can pick the currently active element (3). My goal is to create a locationManager ...

Encountering issues with loading Angular formControl

I've been going through an Angular tutorial on forms, which you can check out here. In my 'datasources.component.html' file, I have the following code: <form [formGroup]="queryForm"> <label>Query: <input type="text" formCont ...

Encountering a "No exported member" error while attempting to include & { session: Express.Session } in the MyContext type while following a tutorial on React, Express, and Typescript

Currently exploring a React, Express, and Typescript tutorial, which is still quite new to me. I am trying to grasp the concept of setting up custom types, and this is what I have so far. In my types.ts file: import { Request, Response } from "expres ...

Component with a dynamic CSS file implementation

I am looking to empower users of my app with the option to select a theme. To achieve this, I have created multiple SCSS stylesheets that offer variations in design elements. However, I am faced with the challenge of loading the appropriate stylesheet base ...

Trapped in a never-ending cycle caused by failing to dispatch an action within ngrx/effects

My current setup involves using Angular2, ngrx/store, and ngrx/effects for state management. I have encountered an issue where I am unable to display an error message when a specific action fails within an @Effects() block. Here is the problematic code sn ...

The debate between TypeScript default generic types and contextual typing

Contextual Typing in TypeScript is an interesting feature where the correct type is inferred from the return value when a generic type is not specified. While it usually works well, there are instances where it can be unpredictable. For example, in some c ...

Exploring the functionality of the Angular snackbar feature

I have created a simple snackbar with the following code: app.component.ts: ngOnInit(){ this.dataService.valueChanges.pipe( filter((data) => data === true), switchMap(() => { const snackBarRef = this.matSnackBar.open ...

Subscription Code Incrementally Triggering Upon Each Component Load

Within the initialization of my component, I have the following code: public Subscription: Subscription; ngOnInit() { this.subscription = this.myService.currentData.subscribe( dataReceived => { this.data = dataReceived; this.useDa ...

Currently, I am working with Angular 11 and encountered some errors while trying to embark on a new project

Command: ng serve Error: Cannot find module '@angular-devkit/build-angular/package.json' View details in "/tmp/ng-lQbnUK/angular-errors.log". These errors occurred when I tried to create the project: Installing packages (npm)... npm WARN depreca ...

Invoking a function in an Angular 4 component using a <td> element

Take a look at this block of code: personListComponent.html <tr *ngFor="let person of personService.getPersons()"> <td (onShow)="getCountry(person)">{{person.name}}</td> <td>{{country}} </tr personListComponent.ts ...

Alter the responseType within Angular (5) once the response has been received

Is it possible to dynamically change the response type in the post method (angular 5) after receiving the response? The challenge: I need the response type to be blob when the response is successful, and json when there's an error. I've searc ...

Can you guide me on how to generate a personalized stamp within the Angular component using Grapecity GcPdfViewer?

When a Pdf is opened in the GcPdfViewer by the User, they are required to stamp the Pdf with an image located in the src/assets folder. However, the example provided on this webpage is not functioning correctly. Can anyone offer me a functioning example? ...

latest version of PrimeNG dropdown is 16.2

I am inquiring about how to implement virtual scrolling in a dropdown menu and connect the virtual scroll with an API backend. Specifically, I would like to know how to trigger an API call when the user reaches the end of the scroll, incrementing the page ...