Protractor is the ultimate way to verify the visibility of an element

Does anyone have a good method for checking if an element is visible using Protractor? Here's what I've tried:

element.isPresent().then(result=>{
      expect(result).toBeFalsy();
});

This works well, but I want to specifically check if the element is visible.

If I use:

element.isDisplayed().then(result=>{
       expect(result).toBeFalsy();
});

The isDisplayed method returns Failed: No element found using locator How can I accurately determine if an element is not visible on the page?

Answer №1

isPresent function will return true if the element is present in the DOM, regardless of whether it is enabled or hidden. On the other hand, idDisplayed function will only return true if the element is present in the DOM and also enabled. It is possible for an element to be displayed but not enabled, requiring a few seconds of waiting before taking action.

 let EC = protractor.ExpectedConditions;
 let waitTime = 3000;  //in ms (3 secs)
 browser.wait(EC.visibilityOf(element), waitTime);

For different types of expected conditions, visit
https://www.protractortest.org/#/api?view=ProtractorExpectedConditions

You can also use the following method:

element.isPresent().then(function() {
expect(element.isenabled()).toBeTruthy();
})

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

How can I make TypeScript's http.get Observable wait for the inline parameter to be returned?

I'm currently facing an issue with my http.get call in which I need one of the parameters (getUserToken) to be returned before the function is executed. However, I don't want to chain them together since the calling function getSomeData returns a ...

How can we create a unique type in Typescript for a callback that is void of any return value?

When it comes to safe callbacks, the ideal scenario is for the function to return either undefined or nothing at all. Let's test this with the following scenarios: declare const fn1: (cb: () => void) => void; fn1(() => '123'); // ...

Exploring the power of the cssContainingText locator feature in Protractor

Currently working on a framework utilizing Protractor, I encountered an issue with the cssContainingText locator from the Protractor API. The locator threw an invalidElement exception, which puzzled me. The structure of the HTML page appears as follows: ...

What is the best approach to re-establish a websocket connection in TypeScript?

Encountering an issue when trying to add a "retry()" method: ERROR in src/app/films.service.ts(28,20): error TS2339: Property 'retry' does not exist on type 'WebSocketSubject'. this.wsSubject.retry().subscribe( (msg) => this. ...

Choose the default setting if angular is null

I'm having an issue with my dropdown select function. <select name="name" [(ngModel)]="name"> <option value="ACTIVE" [selected]="name.status=='ACTIVE' || name.status==null">Active</opt ...

Angular 5 offers the capability to use mat-slide-toggle to easily display and manipulate

I am experiencing an issue with displaying data in HTML using a mat-slide-toggle. The mat-slide-toggle works correctly, but the display does not reflect whether the value is 1 (checked) or 0 (unchecked). Can anyone provide some ideas on how to resolve this ...

Error: The function of splitting 'a' is not available within the context of 'r' (angular.js:263

Although I comprehend the error message, I have not implemented any split functions in my application. The error seems to be originating from the angular.js file itself and is something that has only surfaced recently. I am curious to know if anyone else i ...

Building a multi-platform desktop application using Angular and Electron integrated with ngx

Having developed an Angular application, there is now a need for a desktop version as well. Electron was used to run the application, and everything is functioning as intended. However, an issue arises with localization. In the electron application, only ...

Angular 7's Singleton Service Feature

My service setup looks like this: export abstract class ILoggingService { // abstract functions here } export class LoggingService implements ILoggingService { // service implementation } export class MockLoggingService implements ILoggingServic ...

Is there a way to retrieve a React.Component class by calling a function?

I came across this interesting post: How can I return a class from a TypeScript function? In the linked post above, there is an example of working code: export class Foo {} // Foo is exported export let factory = () : Foo => { // it could be return ty ...

Establish a route nickname for files outside the project directory

I'm currently tackling a project that is divided into multiple angular projects. Within these projects, there are some services that are shared. Is there a way for me to incorporate these services into my project without encountering errors? /root / ...

Combine two observables that are nested inside each other into a single observable

Combining two nested observables into one is my goal. The first observable listens for valueChanges on an input, while the second queries the database. I expect to have a single observable that I can utilize with an async pipe in my Angular template. In t ...

Determine the table data contained within a table located within a specific class

<div class="row-fluid"> <table class="s-table table table-bordered table-striped table-hover"> <thead class="p-table-head"> <tbody class="p-table-body"> <tr> <td&g ...

Define a module function that can be used externally

I am encountering an issue while trying to declare an external module that does not have existing typings. This library has a function that returns a string and takes no arguments. My attempt to define it in a .d.ts file is as follows: declare module "c ...

What are the steps to locally test my custom UI library package built with tsdx in a React.js project

I am currently utilizing tsdx to develop a React UI library, and I am looking to test it within my Next.js project before officially publishing it to the npm package. Initially, I attempted using npm link, which worked initially. However, when I made ch ...

Obtain the closest numerical range using JavaScript

I have a range object and an array of price values. My goal is to find the nearest range from the range object for each value in the price values array. I attempted the solution below, but it did not give me the correct range. range = { 0: '25-500 ...

Tips for creating a unique custom selector function to choose specific properties from an object

While developing a custom hook called useReduxState, I incorporated Redux's useSelector and lodash's pick module. To make it easier to understand, I have simplified my code for this question. Here is a snippet of what I came up with: interface IR ...

What is the process for refreshing the dropdown menu in angular2 after modifying the data in the typescript file?

Right now, I am implementing angular2 in my project. I have a dropdown component labeled as CFC Filter {{val}} In the typescript file, I have defined this.filters = ["0", "60", "100", "180", "600", "1000"]; If the filter value retrieved from the da ...

Error: Unexpected token 'export' in NextJS Syntax

A situation has arisen where a library that was functioning perfectly in an app utilizing react-create-app is now needed for use in NextJS (using npx create-next-app --ts). However, upon attempting to integrate the library, an error was encountered: erro ...

What steps should I take to resolve the issue of my endpoint failing to accept POST requests?

I am in the process of developing a customized API, with an endpoint that is specified as shown below: https://i.stack.imgur.com/sZTI8.png To handle the functionality for this endpoint, I have set up a Profiling Controller. Inside my controller directory ...