webdriverio: [🐛 Bug]: waitForDisplayed( {reverse: true} ) not working for element with style display:none

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.7.2

Node.js Version

20

Mode

Standalone Mode

Which capabilities are you using?

{
    browserName: 'chrome',
    'wdio:enforceWebDriverClassic': true,
    acceptInsecureCerts: true,
    'goog:chromeOptions': {
      args: [
        '--disable-backgrounding-occluded-windows',
        '--window-size=1980,1080',
        '--lang=fr_FR.UTF-8',
        '--disable-search-engine-choice-screen',
      ],
    },
  },

What happened?

Since 9.6.0, When checking waitForDisplayed({reverse:true}) if the element is not displayed (for exemple : style="display: none;" ) -> The API returns that element is displayed

Image

What is your expected behavior?

API should be work correctly

How to reproduce the bug.

To reproduce:

  await browser.url('https://taskmob.demo.vaadin.com');
  await $('#overlay').waitForDisplayed();
  await expect($('.v-loading-indicator')).not.toBeDisplayed(); // OK
  await $('.v-loading-indicator').waitForDisplayed({
    timeout: 5000,
    reverse: true,
  }); // return displayed instead of not displayed

Relevant log output

0-0] 2025-01-29T10:15:27.480Z INFO webdriver: [GET] http://127.0.0.1:4444/wd/hub/session/3dcfa335166a89d72da584f9f219e87d/element/f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72/css/display
[0-0] 2025-01-29T10:15:27.482Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session/3dcfa335166a89d72da584f9f219e87d/execute/sync
[0-0] 2025-01-29T10:15:27.482Z INFO webdriver: DATA {
[0-0]   script: 'checkVisibility(...) [527 bytes]',
[0-0]   args: [
[0-0]     {
[0-0]       'element-6066-11e4-a52e-4f735466cecf': 'f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72',
[0-0]       ELEMENT: 'f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72'
[0-0]     },
[0-0]     { withinViewport: false }
[0-0]   ]
[0-0] }
[0-0] 2025-01-29T10:15:27.500Z INFO webdriver: RESULT block
[0-0] 2025-01-29T10:15:27.506Z INFO webdriver: RESULT true
[0-0] 2025-01-29T10:15:28.679Z INFO webdriver: COMMAND getElementCSSValue("f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72", "display")
[0-0] 2025-01-29T10:15:28.679Z INFO webdriver: COMMAND executeScript("
[0-0]             function webdriverioPolyfill() {
[0-0]   const __defProp2 = Object.defineProperty;
[0-0]   const __name = function(target, value) {
[0-0]     return __defProp2(target, "name", { value, configurable: true });
[0-0]   };
[0-0]   const __globalThis = typeof globalThis === "object" && globalThis || typeof window === "object" && window;
[0-0]   __globalThis.__name = __name;
[0-0] }
[0-0]             webdriverioPolyfill()
[0-0]             return (function checkVisibility(elem, params) {
[0-0]       return elem.checkVisibility(params);
[0-0]     }).apply(null, arguments)
[0-0]         ", <object>)
[0-0] 2025-01-29T10:15:28.680Z INFO webdriver: [GET] http://127.0.0.1:4444/wd/hub/session/3dcfa335166a89d72da584f9f219e87d/element/f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72/css/display
[0-0] 2025-01-29T10:15:28.682Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session/3dcfa335166a89d72da584f9f219e87d/execute/sync
[0-0] 2025-01-29T10:15:28.682Z INFO webdriver: DATA {
[0-0]   script: 'checkVisibility(...) [527 bytes]',
[0-0]   args: [
[0-0]     {
[0-0]       'element-6066-11e4-a52e-4f735466cecf': 'f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72',
[0-0]       ELEMENT: 'f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72'
[0-0]     },
[0-0]     { withinViewport: false }
[0-0]   ]
[0-0] }
[0-0] 2025-01-29T10:15:28.710Z INFO webdriver: RESULT block
[0-0] 2025-01-29T10:15:28.720Z INFO webdriver: RESULT true
[0-0] 2025-01-29T10:15:29.877Z INFO webdriver: COMMAND getElementCSSValue("f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72", "display")
[0-0] 2025-01-29T10:15:29.877Z INFO webdriver: COMMAND executeScript("
[0-0]             function webdriverioPolyfill() {
[0-0]   const __defProp2 = Object.defineProperty;
[0-0]   const __name = function(target, value) {
[0-0]     return __defProp2(target, "name", { value, configurable: true });
[0-0]   };
[0-0]   const __globalThis = typeof globalThis === "object" && globalThis || typeof window === "object" && window;
[0-0]   __globalThis.__name = __name;
[0-0] }
[0-0]             webdriverioPolyfill()
[0-0]             return (function checkVisibility(elem, params) {
[0-0]       return elem.checkVisibility(params);
[0-0]     }).apply(null, arguments)
[0-0]         ", <object>)
[0-0] 2025-01-29T10:15:29.878Z INFO webdriver: [GET] http://127.0.0.1:4444/wd/hub/session/3dcfa335166a89d72da584f9f219e87d/element/f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72/css/display
[0-0] 2025-01-29T10:15:29.879Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session/3dcfa335166a89d72da584f9f219e87d/execute/sync
[0-0] 2025-01-29T10:15:29.879Z INFO webdriver: DATA {
[0-0]   script: 'checkVisibility(...) [527 bytes]',
[0-0]   args: [
[0-0]     {
[0-0]       'element-6066-11e4-a52e-4f735466cecf': 'f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72',
[0-0]       ELEMENT: 'f.62C96CE21D80070DD65E9E507A0B9103.d.D0B30BE2A618968BBF28F9D83A3FD9AE.e.72'
[0-0]     },
[0-0]     { withinViewport: false }
[0-0]   ]
[0-0] }
[0-0] 2025-01-29T10:15:29.906Z INFO webdriver: RESULT block
[0-0] 2025-01-29T10:15:29.913Z INFO webdriver: RESULT true
Error: element (".v-loading-indicator") still displayed after 5000ms
    at <anonymous> (node_modules\webdriverio\build\node.js:5576:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Element.wrapCommandFn (node_modules\@wdio\utils\build\index.js:893:23)
    at async Element.elementErrorHandlerCallbackFn (node_modules\webdriverio\build\node.js:8178:24)
    at async Element.wrapCommandFn (node_modules\@wdio\utils\build\index.js:893:23)
    at async Element.wrapCommandFn (node_modules\@wdio\utils\build\index.js:893:23)
    at async Element.elementErrorHandlerCallbackFn (node_modules\webdriverio\build\node.js:8178:24)
    at async Element.wrapCommandFn (\node_modules\@wdio\utils\build\index.js:893:23)
    at async World.<anonymous> (file://given.js:125:3)

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 20 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I believe the problem is here: https://github.com/webdriverio/webdriverio/blob/dc30cc8863706e3522c78ebb75b0c4a44746aa5b/packages/webdriverio/src/commands/element/waitForDisplayed.ts#L38

This call passes withinViewport as param to isDisplayed and so it skips the default options for checkVisibility which are:

    contentVisibilityAuto: true,
    opacityProperty: true,
    visibilityProperty: true

And if that call was passing visibilityProperty: true to checkVisibility, the case where an element is visibility: hidden; will be covered. I think the default options should always be passed to checkVisibility and only if you pass options those will override the defaults. WDYT @christian-bromann ?

I confirm that the 9.12.3 fixes the problem on our side.

@christian-bromann we encounter similar issues in our projects, if the element completely disapeas from the DOM, it times out instead of concluding that it’s not visible anymore. So we cannot upgrade to v9+ in our projects.

Thanks for the feedback @brickfungus I will take a look!

We have just released it.

We have introduced this change because we don’t want to rely on a custom script for checking the visibility of an element if the Web Platform gives us the ability to check for visibility. It seems like there is an edge case here we haven’t tested for / haven’t considered. Let’s fix that. Eventually we want to get rid of the custom script.

@christian-bromann any thoughts about this? a lot of us are stuck on 9.5 while 9.12 just got released

i’m running into this as well in trying to upgrade to wdio v9+. waitForDisplayed({ reverse: true }) specifically seems to not be able to access the new state of an element when it has changed in the dom, whereas isDisplayed is able to detect when an element changes.

this is causing failures in tests we have that check for elements to display/not display such as loading animations, where we cannot just rely on isDisplayed but need waitForDisplayed({ reverse: true }) to first validate the ui transition has occurred.

edit: in my case, the elements in question are not in the dom at all when this issue occurs. they are not using display: none or visibility: hidden.

i have confirmed that using pause for a few seconds and then isDisplayed will return the correct test results. so the issue seems to be just within the waitForDisplayed command.

When i copy the isElementDisplayed script and check the element, it comes back as false, which is correct Image But somehow i’m getting this error when it’s actually running Image

I’m trying to dig in a bit more and see where in the script it’s getting true

I experienced the same issue just now. I updated wdio from 9.4.3 to latest: 9.10.1 and the test for an element is reported to be displayed, where this element z: index is set so it is below another element and also visibility: hidden; is set.