Skip to content

[BUG] Playwright fails when taking screenshot due to isVisible being true, but should be false #24327

Open
@danielmhair

Description

@danielmhair

System info

  • Playwright Version: v1.35.1, v1.36.1
  • Operating System: Linux
  • Browser: All
  • Other info:

Source code

  • I provided exact source code that allows reproducing the issue locally.

Link to the GitHub repository with the repro

https://github.com/danielmhair/playwright-display-contents-error


First off, you guys are making an amazing product and I absolutely love playwright. I rarely have issues and its very fast. Keep up the good work!


Steps

  • Run the following:
    npm ci
    npx playwright install-deps
    npx playwright test tests/example.spec.ts
    
  • Notice the failed tests

Explanation

I cannot seem to get this exact error in this case, but in my company's site, I get this.

elementHandle.screenshot: Node is either not visible or not an HTMLElement
=========================== logs ===========================
taking element screenshot
  waiting for element to be visible and stable
  element is visible and stable
============================================================

The HTML, defined in the repo above called index.html, has a div with a class tempPositionWrapper. This class has display: contents. Because of this, the element itself does not generate a box in the normal flow of the document. Instead, it behaves as if its contents were inserted directly into the parent element. This causes the element, in this case, to have a computed width, height, x, and y values of 0 when calling getBoundingClientRect(). So I'm wondering if playwright thinks it's visible since it does "technically" have width and height due to its children, but that element directly doesn't because of the style display: contents.

See the image for more clarity:
image

But you will notice one of the failed tests in the repo claim that the element is visible, but it should not be due to your statement in your documentation: "Element is considered visible when it has non-empty bounding box and does not have visibility:hidden computed style. Note that elements of zero size or with display:none are not considered visible", specifically when you state that "elements of zero size are not considered visible".

The reason I mention this, is because the error we get on our company's site states that "Node is either not visible or not an HTMLElement" and as you see in the HTML, our element IS an HTMLElement, so the error is assuming the node is not visible, which is correct. But because the method to get the selector did not throw "Element Not Found" (or something similar), it then proceeded to give back the element.


Expected

Expected isVisible() to return false
Expected queries to the element to throw "Element Not Found" or something similiar.

Actual
isVisible() returns true
Element is returned
Screenshot was called and throws "Node is either not visible or not an HTMLElement"

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions