I have a section on my HTML page which is not visible “optically”. but if i scroll down or if i click on a link, the section should be visible “optically”.
I would like to check that the section is visible optically. I try to use “Element Should Be Focus” but it doesn’t work.
Is it possible to verify that the element is visible optically on the page?
Thank you for advance
Element Should Be Focused as the name describes is the element that has focus, for example if you clicked on a username field or just set the username value then the username field should pass
Element Should Be Focused but you would expect the password field to fail Element Should Be Focused.
Element Should Be visible cannot be use to check if an element is optically visible
Verifies that the element identified by
locator is visible.
Herein, visible means that the element is logically visible, not optically visible in the current browser viewport. For example, an element that carries
display:none is not logically visible, so using this keyword on that element would fail.
See the Locating elements section for details about the locator syntax.
message argument can be used to override the default error message.
In that case, unfortunately there is no keyword for what you asked.
You’ll have to either
- “trust” the browser, that what it reports as logically visible is actually what is optically visible
- or verify it independently outside the browser, meaning using another library to take a screenshot of the browser that SeleniumLibrary launched and compare that screenshot to a known expected screenshot
I think what the help was alluding to is an element could be logically visible but because of window size it might not be optically visible because you’d need to scroll to it, unfortunately I don’t think there is a way that SeleniumLibrary can know this is the case, and this is something that will vary from client to client.
i.e. a first generation iPhone has a much smaller screen area than a desktop with a 4K monitor, likewise 2 people using 1080p monitors, one might use the browser maximised to full screen and no screen scaling and the other might use a windows browser with 200% screen scaling both would give very different results
It really depends on
- how “standardised” your environment is (i’d hope your employer/customer allows individuals to at least set the screen scaling based on their visual requirements and not discriminate against the visually impaired),
- what your requirements are, are you testing the browser itself (working on a browser development team) and whether it correctly handles the display CSS classes correctly, or are you just testing a web application and can trust that the browser is probably following the rules?
Hope that makes sense,