How to use Selenium-Webdriver (Java Script) to wait for an element to vanish

driver.wait(until.elementIsNotVisible(By.css(".popup-backdrop fade")), 15000);

Is there a way to wait for the ".popup-backdrop fade" overlay to disappear before proceeding with element click?

I am working with Selenium-webdriver using JavaScript, not Java, Python, or C#.

Answer №1

I couldn't find the negative wait in the code source, but one possible solution is to create your own condition:

var webdriver = require('selenium-webdriver');
var until = webdriver.until;
var By = webdriver.By;

until.elementIsNotPresent = function elementIsNotPresent(locator) {
  return new until.Condition('for no element to be located ' + locator, function(driver) {
    return driver.findElements(locator).then(function(elements) {
      return elements.length == 0;
    });
  });
};

driver.wait(until.elementIsNotPresent(By.css(".popup-backdrop fade")), 15000);

Answer №2

According to the comment on the approved response, it seems that until.Condition is not a recognized constructor in Selenium 4. However, there is an alternative approach:

const { By, until, Condition } = require('selenium-webdriver');

until.elementIsNotPresent = function locateElement(locator) {
  return new Condition('to check if no element exists at ' + locator, function(driver) {
    return driver.findElements(locator).then(function(elements) {
      return elements.length === 0;
    });
  });
};

More information about using Condition can be found at: https://github.com/seleniumhq/selenium/issues/2755

Answer №3

This is an alternative solution to the problem that is more streamlined and effective compared to the accepted answer which results in a "TypeError: until.Condition is not a constructor" error:

    Utilizing this code snippet will ensure that the program waits until the 'loadingIndicator' element disappears before proceeding:
   
    await this._webDriver.wait(() => {
        return this._webDriver.findElements(By.id('loadingIndicator')).then(function(found) {
            return found.length === 0;
        });
    }, 3000, 'The element should disappear');

Answer №4

Here is an alternative approach that you might consider:

const elementClass = webdriver.By.css('.element-class');
driver.wait(webdriver.until.elementLocated(elementClass));
let foundElement = driver.findElement(elementClass);
driver.wait(webdriver.until.elementIsVisible(foundElement));
driver.wait(webdriver.until.elementIsNotVisible(foundElement));

Answer №5

Exciting update: now integrated!

Great news! The elementIsNotVisible feature has been included in the latest version of selenium webdriver 4.0.0-beta.3. It seems to have been added after previous answers were shared.

Take a look at how to use it:

const timeout = 60 * 1000; // 60 seconds
const element = await driver.findElement(By.id(elementId));

// This line is crucial 
await driver.wait(until.elementIsNotVisible(element), timeout);

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 are some methods for creating nested asynchronous calls in jQuery?

Here is an example in main.js: $.when( $.get('foo/bar.html'), $.get('lorem/ipsum.html') ).done(function(data1, data2){ someCode(); }); In lorem/ipsum.html: $.when( $.get('otherStuff.html'), $.get(' ...

Issue with electron-vue: Unable to modify Vuex state when using RxJS subscribe

I need help with my code involving two functions in the mutations and two pieces of state const state = { files: [], uploadProgress: 0 } const mutations = { SET_UPLOAD_IMAGE: (state, files) => { state.files = files }, UPLOAD_IMAGE: ( ...

Is there a way to modify the color of my question post-submission?

Within my code, there are numerous queries that need to be addressed. Upon submission, I desire to alter the color of each question to green if the response is correct, or red if it is incorrect. document.getElementById("submit-button").addEventLi ...

Showing a series of JavaScript countdowns consecutively

I am working on a project where I want to display a second countdown after the first one finishes using meteor. The initial timer code looks like this: sec = 5 @timer = setInterval((-> $('#timer').text sec-- if sec == -1 $('#time ...

Routes inoperative as intended

When using a standard expressroute for this login, I have noticed that even if the req.body.password is incorrect, I am still getting redirected to '/login'. router.post('/student/login', (req, res) => { if (req.body.password === ...

"Phraseapp is in the process of refreshing the primary language document

I currently have a locale file that contains various text keys that need to be translated. Each key corresponds to a specific text that needs to be translated into different languages: { key1: "Text to translate", key2: "Another text to translate", ...

Automatically switch to dark mode at specified times: A simple guide

Here is the current method for toggling themes: let themeToggler = document.getElementById('theme-toggler'); themeToggler.onclick = () => { themeToggler.classList.toggle('fa-sun'); if (themeToggler.classList.contains('f ...

Other elements are unable to conceal Material UI InputBase

Displayed below is a navigation bar that sticks to the top, followed by rows of InputBase components from material-ui. Despite setting the background color of the nav bar to white, the input always appears above the nav. This strange behavior stopped when ...

Press the button within the <span> element using Python Selenium

I am attempting to select the download button. Here is the HTML code for the button: <a class="x-btn toolbar-menu x-unselectable x-box-item x-toolbar-item x-btn-transparent-medium" style="padding: 0px 5px; right: auto; left: 1121px; margi ...

What is the process for retrieving a txt file and comparing it with an array to create a dropdown list using webdriver in java?

Let's imagine this scenario: 1) Start by creating a file with the input string "Sep 2015". 2) Gather the drop-down list options into an array. 3) If the array matches the string in the file, exit the loop. Otherwise, download a new month report and o ...

React: Issue with array rendering order after initial render

After the initial rendering of my array in the correct order, any subsequent changes to it result in the same rendered order. Let's consider this scenario: initializeArray() { this.state = { test_array: [1,2,3,4] } let self = t ...

Infusing JavaScript with vibrant images

I am currently facing an issue where I am trying to insert images with JavaScript attached to them. Oddly enough, it seems to work fine on Firefox but the images or icons do not display on Internet Explorer. This is how I have written the code: <a hre ...

Managing these kinds of Popups in Selenium WebDriver with the help of Java

Looking for advice on handling these types of popups with Selenium using Java. I attempted to use the getWindowHandles method, but I'm having trouble figuring out the issue. ...

Determine the character's position in an input field by tracking mouse movements

I am in need of a way to determine the position of a character in an input field based on mouse movement. For example, if the input field contains the value 'abcde' and I hover my mouse over the character 'a', the position should be ...

Local error when attempting to export a node module

As a novice in node.js, I'm looking to parse an XML file into JSON. To achieve this, I decided to use the bluebutton library available at https://github.com/blue-button/bluebutton.js. After installing the module using npm install bluebutton, a node_m ...

Conceal Child Component Element Upon onClick Event with ReactJS

As someone new to React, I am learning by coding. Currently, I have component A which includes a select element with menu items (all material UI). Is it possible for the whole component to disappear once a user chooses an option from the dropdown? Essentia ...

Implement Next.js deployment on NGINX server with a 403 forbidden error

I am currently utilizing Next.js for the frontend and Django for the backend. During development, everything is functioning properly. However, when transitioning to production, I am encountering a 403 Forbidden Error related to /_next/static/chunks. It app ...

What is causing the TypeError in Discord.js when trying to read the 'voice' property? Any help troubleshooting this issue would be greatly appreciated

Hey everyone, I'm having an issue with my play.js file that I obtained from a Source Bin. If anyone could provide some assistance, it would be greatly appreciated. const ytdl = require("ytdl-core"); const ytSearch = require("yt-search"); //Global que ...

Screenshot of TestNg Report

When it comes to using TestNG for reporting, I often attach screenshots as hyperlinks to test cases using Reporter.log. However, the issue arises when these screenshot file paths are located on my local system folder. How can others access these screensh ...

Using HTTPS, you can access Flask from AJAX

I have encountered numerous inquiries concerning this issue, but none have proven effective for me. I recently switched my domain from HTTP to HTTPS. Everything was functioning properly on HTTP. The main issue lies in the fact that my javascript and flask ...