Issue with selenium webdriver isDisplayed() method in Javascript

I am currently developing a test using Selenium and JavaScript.

During one part of the test, I need to go through an array of input elements and fill in values for those that are visible.

if (textInputs.length > 0) {
    console.log('handling text input');
    var i, textInputLen;
    for (i = 0, textInputLen = textInputs.length; i < textInputLen; i++) {
      (function (index) {
        if (textInputs[index].isDisplayed()) {
            textInputs[index].sendKeys("custom text box - " + textBoxes);
            textBoxes++;
        }      
      }(i))
    }
  }

However, I keep encountering the error message

ElementNotVisibleError: element not visible
when trying to fill in inputs that are not displayed on the DOM. What could be causing this issue? And how can I resolve it?

I have attempted different methods instead of using isDisplayed():

  1. I ran JS code to check if the element had visibility set to hidden or display set to none. The problem here is that the element being displayed could result from various reasons, so I am searching for a more universal solution. In this scenario, utilizing isDisplayed() would be ideal.

Please provide guidance on how to address this issue.

Answer №1

When using the method .isDisplayed(), it is important to note that it returns a promise rather than the actual displayed state. To retrieve the resolved result, utilize then in the following manner:

element.isDisplayed().then(function(status){
    console.log(status):
});

An alternative approach involves filtering a list of elements using webdriver.promise.filter:

var checkboxes = driver.findElements(By.css("input[type=checkbox]"));

webdriver.promise.filter(checkboxes, function(element) {
    return element.isDisplayed();
}).then(function(element) {
    element.click();
});

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

A guide on extracting a JSON data with a BigInt type using TypeScript

I am facing an issue with parsing a bigint from a JSON stream. The value I need to parse is 990000000069396215. In my TypeScript code, I have declared this value as id_address: bigint. However, the value gets truncated and returns something like 9900000000 ...

Testing Playwright API against a corporate proxy results in timeouts and failures

While my Playwright UI tests utilizing page are running smoothly, I have encountered issues with the API tests. Specifically, when attempting a call like const response = await request.get('https://reqres.in/api/users/3'). I suspected that the p ...

Changing the names of elements within an array of objects using Javascript in a React application

I have a large array of objects that needs its keys changed. I want to map over the array and update key names, such as changing "job_id" to "id" and "job_title" to "name", among others. How can I efficiently perform this task on thousands of items? Arra ...

Characteristics of events within the embed element

<div id='aplayer'></div> js $('#note').click(function() { $('#aplayer').html("<embed src=" + music + " onended='test();'" + ">"); }); function test(){ alert ('525'); } audio is ...

Expandable menu using jQuery

Currently, I am experimenting with an Accordion Menu plugin called example 3: Non-accordion (standard expandable menu). My goal is to set up a menu structure where there are 5 options. Two of these options have sub-menus, while the other three are direct ...

Raphael and Safari: The Perfect Pair

Lately, I've been working on a project using Raphael 2.0.1 and after running some cross-browser checks, I noticed that text is not displaying correctly in Safari. It seems like the 'dy' attribute is inheriting the value of the 'y' ...

Viewing HTML files remotely using Kendo UI Mobile

I developed a sample hybrid app using the Telerik App Builder CLI. The project features an initial home screen loaded from a COMPONENTS folder within the project. Within the Components folder, there is a Home folder containing an index.js and view.html fil ...

Material UI does not support the inline attribute for applying CSS properties

Trying to adjust the CSS for Material-UI When setting the width, everything works fine. However, when attempting to set display inline, an error occurs ---> "inline is not defined" Can anyone provide guidance on how to resolve this issue? Sharing my cod ...

Integration of Selenium with Java using TFS

Recently, I've developed Selenium tests using Java in Eclipse. Meanwhile, I also have manual test cases stored in TFS. Is there a method to automate the process of updating the test status in TFS through Java code? ...

ACE.js enhances website security through Content Security Policy

I've been working on setting up a helmet-csp with ace running smoothly. Here's how my helmet-setup looks: var csp = require("helmet-csp"); app.use(csp({ directives: { defaultSrc: ["'self'", "https://localhost:8000"], ...

Locating elements effortlessly using Selenium and Capybara: Search for selectors within any element

Imagine we have a <div class='something-else'> and buried deep within it lies an element <div class='inside-something-else'> My goal is to find a way to locate that specific inside-something-else-div using the methods of Ca ...

What is the best way to implement alphabetical pagination using Material UI Pagination?

I am attempting to display a list of words using MUI pagination, arranged in alphabetical order. Previous format 1,2,3,...,26 Desired format A,B,C,...,Z wordsList: { A: [], B: [], ..., Z: [] } ...

What method do Python developers typically use for managing data effectively?

Currently, I have around 30 lists, some dictionaries, most of which contain at least 200 items consisting of integers and strings. To gather this data, I utilize selenium and beautiful soup for scraping the html. The information is then organized into nam ...

The custom error page in NextJS is failing to display

In my custom pages/404.ts file, I have coded the following: export default function NotFound() { return <h1>404 - Page Not Found</h1> } Additionally, there is another page that displays a 404 error when the organization is null: import Error ...

Is there a way to conceal my button menu when printing?

I'm trying to create a button that prints out the current page, but I want to hide my menu of buttons (which is contained inside 'mainMenuDiv') when I go to print. However, so far, all my attempts have resulted in an error saying 'uncau ...

Sending Data from Dialog Box1 to Dialog Box2 in ASP.NET Using JavaScript

Is there a way to successfully transfer a value from Modal1 to Modal2? I am facing an issue where Modal1 opens Modal2 to receive a necessary value, but I keep encountering the error message: "Uncaught TypeError: Cannot read property 'click' of nu ...

Conquering disparities in standards mode with Javascript

Having an issue with this code snippet: function scrollLeft() { document.body.scrollLeft -= scrollSpeed; } While it works fine in Chrome and Safari, it doesn't seem to work in IE and Firefox. Found out that the problem lies in the fact that Fire ...

Modify the value of the 'key' within an array in JavaScript

Here is the array I am working with: [ { "id": 2, "language": { "name": "English", "abbreviation": "EN" } ] To access the value of language.name: function get(arrName) { for(var k = 0; k < arr.length; k++) { ...

Is there a way to identify when the back button on an Android device is pressed while using a

I am currently working on a Progressive Web App with Vue.js. I am aware that Cordova has the capability to handle the back button on Android/iOS devices (not the browser's back button) which is good news. Does anyone know how I can detect this in Vue ...

A guide on dynamically using jQuery to embed an image within a hyperlink tag

I am having trouble with these HTML tags: img = <img data-dz-thumbnail="" target="_blank" alt="twitter-btn-mob.png" src="image.jpg"> a = <a href="javascript:void(0)" target="_blank"></a> My goal is to insert the image tag into the anc ...