Add assertElementVisible and assertElementNotVisible Commands
Please add verifyVisible and verifyNotVisible as they are helpful in verifying elements being present but not visible to the user.
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.
Work around for checking if it's hidden
| Command | Target | Value |
|---|---|---|
| execute script | return document.querySelector('input#id').style.display; | display |
| assert | display | none |
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 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.
I just don't wanna confuse anyone, since the implementation used by WebDriver is much more complex.
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.
#105 @corevo says add an issue for verifyNotVisible. Is this that issue, or do we need to make another one?
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
displayproperty set tonone...