Having trouble with CSS Locator identifying an element in your Protractor Test?

In the Protractor test snippet below, I am attempting to calculate the quantity of div elements using the CSS locator:

let list = element.all(by.css('div[class="ag-header-cell ag-header-cell-sortable"]'));
expect(list.count()).toBe(11);

Although there are visibly 11 divs with this specific class, my test is inexplicably only registering 10. Consequently, the test fails with the following error message:

Expected 10 to be 11

https://i.stack.imgur.com/SNyGJ.png

To identify the unacknowledged div, I printed out the text content of each one:

element.all(by.css('div[class="ag-header-cell ag-header-cell-sortable"]')).each((it) => {
    it.getText().then((text) => {
        console.log('Text', text);
    })
})

The div with col-id='Ni' does not seem to be recognized, despite meeting the specified CSS class criteria in the test.

If anyone can shed light on why this discrepancy is occurring, I would greatly appreciate it.

Answer №1

After some trial and error, I finally got the locator to work by implementing this function:

element.all(by.css('div.ag-header-cell'))
    .map(function (cell) {
        return cell.getText();
    })
    .then(function (cellValues) {
        expect(cellValues).toEqual(["1st Expected Result", "2nd Expected Result"]);
});

This solution successfully retrieves all 11 values that were previously unreachable with my initial code.

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

What is the best way to access dependencies that are externally defined in the root package.json file?

I'm unsure of the appropriate terminology for this concept. If you have the correct TERM to share or a reference for me to learn more about it, please provide the link. Currently, I am examining our extensive package.json file for various projects. ...

Looking to execute a service method within an authguard service?

I am a beginner with Angular and I am looking to invoke a service method within the authguard service. The specific service function that I need is as follows. Please note that I do not want to make any changes to this service function. loadOrganizations() ...

Struggling with Angular 5 Facebook authentication and attempting to successfully navigate to the main landing page

I have been working on integrating a register with Facebook feature into an Angular 5 application. Utilizing the Facebook SDK for JavaScript has presented a challenge due to the asynchronous nature of the authentication methods, making it difficult to redi ...

When checking for a `null` value, the JSON property of Enum type does not respond in

Within my Angular application, I have a straightforward enum known as AlertType. One of the properties in an API response object is of this enum type. Here is an example: export class ScanAlertModel { public alertId: string; public alertType: Aler ...

Creating a contact page with Font Awesome icons similar to my design using Flexbox in CSS

How can I achieve the desired layout for this image? I have written some code and applied CSS to get the output, but I encountered an issue. When the text in my address section is too large, the icon gets misaligned and collapses. How can I fix this issue ...

Unable to fetch packages from npm or github using jspm install because of proxy configuration restrictions

I'm attempting to execute a basic Angular 2 unit test application. I have cloned the following git repository and followed the steps provided in the readme file: https://github.com/matthewharwood/Hit-the-gym I have configured proxy settings for npm, ...

Integrate jQuery-ui into your Angular 5 application

Having some trouble integrating jquery-ui into my Angular 5 project. I need to use a feature that requires jquery-ui, but I keep encountering this error: TypeError: WEBPACK_MODULE_10_jquery(...).droppable is not a function I initially attempted to plac ...

The Conundrum of Angular 5 Circular Dependencies

I've been working on a project that involves circular dependencies between its models. After reading through this StackOverflow post and its suggested solutions, I realized that my scenario might not fit into the category of mixed concerns often assoc ...

Ensure that you only run `npm publish` in the Angular monorepo if there

In my angular monorepo, I have an "app" and a library that is published as its own npm package. The publishing process is automated on a CI environment. Previously, the library and app had separate build jobs. Now that they are built together, I am encount ...

Issues with hidden overflow and height attributes not functioning correctly in Internet Explorer 9 when using the DOCTYPE HTML standards mode

I have a <div> with overflow:hidden and height:100% that adjusts the div contents to fit the window's height on Chrome and Safari. However, in IE9, the div does not respect the styles of overflow:hidden and height:100%, causing it to expand to ...

The table is appearing incorrectly on the screen

I am working on displaying a list of elements in a table. To achieve this, I have created two components - the tableComponent and the tableitemComponet. In the tableComonent, I have implemented the following: <table class="table"> <thead> ...

The css property of *ngContainerOutlet is ineffective when applied to an ng-component with encapsulation

When I utilize *ngContainerOutlet to dynamically insert components, it wraps the component's template within an ng-component tag which causes my CSS styles to become ineffective. For example: <div class="my-class"> <ng-container *ngComp ...

Updating reactive form fields with patched observable data in Angular

Struggling with initializing a reactive form in my component's onInit() method, as well as handling data from a service to update or create entries in a MySQL table. The issue lies in using patchValue to pass the retrieved data into the form: compone ...

How can functions be tested using Jasmine without them being exposed?

In my project, I have a file called utils.js which contains several utility functions. To expose some of these functions while keeping the rest hidden, I utilize module.exports. module.exports = { utils_1: function_1, utils_2: function_2 }; Howe ...

When applying a cell formatter to change the color of a Tabulator cell, the text displayed is being

I am attempting to dynamically change the color of a tabulator cell based on its input. My initial approach was to simply try changing the cell's color. After running the following code, here is what I observed: function testFormatter(cell, formatt ...

Wookmark js isn't designed to generate columns from scratch

I am attempting to utilize the Wookmark jQuery plugin in order to create a layout similar to Pinterest. However, I am encountering an issue where Wookmark is not creating columns within the li elements, instead it is simply stacking images on top of each o ...

Bootstrap 3 Implementation of a Clear Navbar

I'm trying to create a transparent navbar using the code below: <div class="navbar navbar-default navbar-fixed-top" style="top:50px; background:transparent;"> <div class="navbar-inner"> <div class="container"> <ul cla ...

The component is not being activated by the subject subscribe

I'm having trouble subscribing to the Subject folder_id in the board component when passing the id from the files component. The boardId function is called when a button is pressed in the files component. The activateId is retrieved from the URL snap ...

The data type 'string' cannot be assigned to the data type 'Position'

Currently, I am in the process of converting React js to typescript. The component being used is a Class Component. I would like to obtain CSS settings through props and apply them to an element. How can I resolve this issue? render(){return( <span st ...

The table's pagination displays above, thanks to Tailwindcss

I'm facing an issue where the pagination is showing up above the table, but I was expecting it to be displayed after the table. It would be ideal if the pagination appeared right after the table when adding multiple rows. Check this link for more inf ...