selenium-ide icon indicating copy to clipboard operation
selenium-ide copied to clipboard

Add assertElementVisible and assertElementNotVisible Commands

Open hohnan opened this issue 8 years ago • 8 comments

Please add verifyVisible and verifyNotVisible as they are helpful in verifying elements being present but not visible to the user.

hohnan avatar May 23 '18 12:05 hohnan

Any update on this? My test cases rely heavily on these to functions and they are the last things I need to allow me to move to the new version.

MargateSteve avatar Sep 07 '18 12:09 MargateSteve

Work around for checking if it's hidden

Command Target Value
execute script return document.querySelector('input#id').style.display; display
assert display none

hvlucas avatar Sep 21 '18 15:09 hvlucas

I wouldn't recommend using that workaround, because there are plenty of other attributes that may affect element's visibility, to name a few:

  • opacity
  • visibility
  • position
  • z-index

It is one of the more useful commands to have in the kit, and we will make sure to add them.

corevo avatar Sep 21 '18 16:09 corevo

@corevo Of course, this was specific to test if a JS function was triggering display: none;
There are ways to check opacity, visibility, position and z-index with Javascript as well.

hvlucas avatar Sep 21 '18 16:09 hvlucas

I just don't wanna confuse anyone, since the implementation used by WebDriver is much more complex.

corevo avatar Sep 21 '18 16:09 corevo

Do the V3.4.0 new commands "wait for element visible" / "wait for element not visible" somewhat resolve this request? I, too, was looking for verify visible, but was able to use this wait command to perform similar check.

luquitia avatar Oct 08 '18 21:10 luquitia

#105 @corevo says add an issue for verifyNotVisible. Is this that issue, or do we need to make another one?

eyleron avatar Mar 19 '19 21:03 eyleron

About the "visible:hidden", "opacity:0", "z-index:-1" or any "position:..." attributes: Those attributes do not hide an element. They hide the contents, but the element still takes up width/height in the document structure. The only way to actually hide an element from the document is setting "display:none".

And also note, that the tested element itself might be visible, but any parent of that element could be hidden.

Here's the most reliable way I found to test for hidden elements:

Command Target Value
execute script return null === document.querySelector('input#license-key').offsetParent isHidden
assert isHidden true

The "offsetParent" solution is based on the top note on the MDN documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent

offsetParent returns null in the following situations • The element or its parent element has the display property set to none ...

stracker-phil avatar Sep 18 '20 13:09 stracker-phil