Verifying the visibility of an element

I am facing a challenge with a list of apps displayed on a non-angular page. The availability of these apps depends on the subscription level purchased by the user. Even if an app has not been purchased, it is still listed but displayed with an overlay (please refer to the image).

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

Here is an example of the HTML structure:

<div class="apps-item apps-no-border disabled">
  <div class="apps-name">
    <span>Interactive Event Diagrams</span>
  </div>
  <div class="divider">
    <div class="apps-description">Interactive Event Diagrams is an indispensable online tool, allowing website visitors to view your meeting rooms and create their own customized event layouts according to their specific needs, all while using your venue’s available inventory. Users
      can email and save diagrams or images for future reference.</div>
    <div class="apps-image-preview">
      <img alt="Interactive Event Diagrams" src="/Content/Images/AppsPreview/interactive_event_diagrams.png">
    </div>
    <div class="apps-action">Not Purchased</div>
    <div class="overlay"></div>
  </div>
</div>

If an app is purchased, the overlay element in the HTML is shaded gray and not visible on screen. (For example, there is no grey shading over Hotel Venue Explorer) I need to verify whether the overlay is visible or not.

This is the approach I have tried:

elm = element.all(by.css('div.apps-item')).get(5);
expect(elm.$('div.overlay').isDisplayed()).toBeTruthy();

However, the expect statement is returning false. Look at the HTML for other apps where the overlay class has gray shading.

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

Answer №1

When dealing with a div.overlay that is always present in the DOM, it can be tricky to determine if it is displayed since it will constantly be there and its visibility might be controlled by CSS and JavaScript. The usual method of using `isDisplayed` function for an empty HTML element may not work in this case.

To confirm the display status, one approach is to check for specific CSS attributes responsible for the greying out effect. Here's how you can do it:

elm = element.all(by.css('div.apps-item')).get(5);
//Specify the CSS attribute used to grey out the apps-item div such as height, width, color, etc...
expect(elm.$('div.overlay').getCssValue('background-color')).toEqual('grey'); 
expect(elm.$('div.overlay').getCssValue('width')).not.toBeNull(); //If the width is known, equality or greaterThan(someVal) can be checked.
expect(elm.$('div.overlay').getCssValue('height')).not.toBeNull();

I hope this explanation is beneficial to 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

Getting duplicate tokens for multiple users while utilizing Firebase messaging

When attempting to acquire a token from firebase, I employ the code snippet provided below: const messaging = firebase.messaging(); messaging.requestPermission() .then(() =>{ return firebase.messaging().getToken(); }).then(token => { s ...

The navigation items in the hamburger menu on amazon.ca can be difficult to locate using xpath, leading to inconsistencies in the

I am currently working on a selenium/cucumber project with the following requirements: Visit amazon.ca Click on the menu icon (located in the top left corner) Navigate to Kindle under Digital Content and Devices Select Kindle under Kindle E-Reader section ...

Calculating the total value in a Laravel database

Is there a way for me to calculate the number of apartments in a project based on the floor they are located on? This is db $table->id(); $table->unsignedBigInteger('project_building_id')->nullable(); $table->unsignedBigInteger(&apos ...

Unknown identifier in the onClick function

I want to create a JavaScript function that can show or hide a paragraph when clicking on an arrow. The challenge I'm facing is that I have a list of titles generated in a loop on the server, and each title is accompanied by an arrow. Initially, the c ...

Determine the previous day's date using JavaScript by subtracting one day

I am facing an issue while attempting to store a specific date format in MongoDB. Instead of saving the date as intended, it is consistently registering a day earlier than specified. For instance - db.test.insert({name: "test1", dob: new Date(1986, 11, ...

Easy task tracker in Vue.js

I’m currently delving into the world of VueJS and working on a simple to-do list application. The issue I’m facing is that I can't seem to successfully pass an array to the child component responsible for displaying the list: Parent Component < ...

Unable to maintain sequential IDs for textboxes using Javascript or JQuery

I am encountering a problem involving the addition and deletion of multiple text boxes using buttons. The issue lies in maintaining sequential IDs for each textbox. Below is an explanation of my code: <div class="form-group" id="intro-box"> < ...

Is it possible for a function parameter to utilize an array method?

Just starting to grasp ES6 and diving into my inaugural React App via an online course. Wanted to share a snag I hit along the way, along with a link to my git repository for any kind souls willing to lend a hand. This app is designed for book organization ...

The onload function in jQuery is not functioning properly when the page is refreshed

I'm just starting out with jquery and I have a simple project in mind. The idea is to have two pictures stacked on top of each other, but I want the page to start showing the second picture first (at a specific scroll point). Then as the user scrolls ...

AngularJS Date Selection with UI Bootstrap Tool

Just starting out with AngularJS and looking to add a datepicker to my project. I'm using angular.min.js version AngularJS v1.5.0-rc.1 ui-bootstrap-tpls-0.12.0.js version 0.12.0. There are so many examples online that it's confusing. How do I go ...

Replicate the preceding input data by simply clicking a button

Here is some HTML and jQuery code that I am working with: $(".btn-copy").click(function() { var previousContent = $(this).prev()[0]; previousContent.select(); document.execCommand('copy'); }); <script src="https://cdnjs.cloudflare.com ...

Using a static function within a library's state function in NextJS is throwing an error: "not a function"

Inside a library, there's a special class known as MyClass. This class contains a static method named setData. The contents of the MyClass.js file are shown below: class MyClass { static DATA = ''; static setData(data) { MyClass ...

Guide on serving static HTML files using vanilla JavaScript and incorporating submodules

Is it possible to serve a static html file with elements defined in a javascript file using imports from submodules using vanilla JS? Or do I need bundling tools and/or other frameworks for this task? Here's an example code structure to showcase what ...

Struggling to make an AJAX form function properly

I'm running into an issue while setting up a basic AJAX form. My goal is to have a message display on the same page upon successful login using a PHP form through AJAX, but currently, I get redirected to the PHP file after form submission. Can anyone ...

Angular checkbox ng-checked feature not functioning as expected

I attempted to utilize checkbox and link the checked attribute using ng-checked attribute, however it seems to be not functioning properly. Interestingly, it works perfectly fine with ng-model attribute on checkbox type inputs. <!-- not working --> ...

Automatically update certain attributes of an object with Spring MVC's auto-refresh feature

Currently, I have a table in JSP where I am populating all object attributes using Spring MVC. The backend is providing a list of DTO's which are then being added to the ModelView. In the JSP, we iterate through this DTO list and display it in the tab ...

When the enter key is pressed and a text is entered on the same line or under a specific condition

Is it possible to input text and press the enter key using a single statement? I attempted to separate the steps of inputting text and pressing the enter key. Can this be achieved in just one statement? WebElement department = driver.findElement(By.xpat ...

Is there a way to extract the MIME type from a base64 string?

My base64 String appears as "UklGRkAdEQBXQVZFZm10IBIAAAABAAEAg...". I am attempting to download this file using my browser. Therefore, I convert it to a blob with the following function: b65toBlob: function(b64Data, sliceSize = 512) { ...

What is the best way to continuously monitor MongoDB for updates and sync them with my user interface?

Looking to continuously monitor a user's notifications in MongoDB, updating them on specific actions and displaying updates on my React frontend without reloading every time the user logs in. I am currently utilizing Node and Mongoose models for datab ...

Unexpected behavior encountered in Rails app with unobtrusive JavaScript

I'm facing an issue with my link_to setup. Here's what I have: <%= link_to "Load More", comments_feed_path(@post.id), :id => 'my-link', :remote => true %> In my application.js file, I have the following code: $( document ...