Using "verifyVisible" and "verifyNotVisible" commands in selenium
Sometimes during running the script, you need to verify that specified element on the page is visible or hidden. You can use "verifyVisible" and "verifyNotVisible" commands only for the verification of the element visibility on the page. It will return just "True" and "false" based on the element visibility on page but it will not
take any action on that element or script.
take any action on that element or script.
"verifyVisible" command
"verifyVisible" command will return "false" in log if targeted element is not available(hidden) on page and selenium will continue to execute next commands.
"verifyNotVisible" command
"verifyNotVisible" command will return "true" in log if targeted element is available(visible) on page and selenium will continue to execute next commands.
Let me show you both commands with example
New Test | ||
Command | Target | Value |
open | http://www.w3schools.com/css/css_display_visibility.asp | variableA |
verifyVisible | css=#imgbox2 > input.box | |
verifyNotVisible | css=#imgbox2 > input.box | |
pause | 5000 | |
click | css=#imgbox2 > input.box | |
pause | 2000 | |
verifyVisible | css=#imgbox2 > input.box | |
verifyNotVisible | css=#imgbox2 > input.box |
In above example, "verifyVisible" command (2nd command in example) will verifies that targeted element "Box 2" is visible on the page or not and it will be pass because on initial level of script, it is visible.
Now next command "verifyNotVisible" (3rd command in example) will look on to the page but with reverse condition (It will look for element "Box 2" not present on to the page). It will return true in log because element element "Box 2" is visible on the page.
Now selenium will hide "Box 2" by clicking on "css=#imgbox2 > input.box"(5th command in example)
Once again "verifyVisible" (7th command in example) will verifies element visibility on page but right now element "Box 2" is not visible on page so it will return "false" in log.
Last command will be pass because now element is not present on the page.
No comments:
Post a Comment