Using selenium "verifyelementpresent" and "waitForElementPresent" commands with example

How to use "verifyElementPresent" in selenium

"verifyelementpresent" command in selenium is useful for verification of element presence on page. Selenium ide will verify element present and return "[error] false" if targeted element is not present on page. Else it will becomes pass. Verify element present in selenium will check availability of element on page. I have recorded best example as bellow for "verifyelementpresent" command to describe how verify element present in selenium ide works. This command of selenium will check if element is present on page.

Using "waitForElementPresent" command to waiting for element

Sometimes elements takes time to appear on page when you are navigating through pages or clicking on
buttons or doing something else. "waitForElementPresent" command will pause selenium until targeted element not present on the page. Once element will appear on the page, selenium will go for executing next command.

Let we see selenium IDE "verifyelementpresent" and "waitForElementPresent" commands with example.

Example : 1
New Test
CommandTargetValue
openhttp://w3schools.in/demo/custom-lightbox/
clickid=more
verifyElementPresentcss=span.button1.close
clickcss=span.button1.close

VIEW EXAMPLE OF "verifyElementPresent" IN WEBDRIVER

In 1st example, "verifyElementPresent" command will return "[error] false" in log because that command was executed before element "css=span.button1.close" ("Close" button on popup message) appears on the page. Popup taking sometime(1 to 2 seconds) to open and selenium executing both the remaining commands ("verifyElementPresent" and "click") during loading of popup. So selenium can not find targeted element "css=span.button1.close" and your script will becomes fail. How can we handle this situation ?

See in below example, I have inserted one more command "waitForElementPresent" just after "click" command. It will pause selenium until element "css=span.button1.close" appears. Once that element appears on the page, selenium will execute remaining commands. Try both example yourself ti understand them better.

Example 2 :
New Test
CommandTargetValue
openhttp://w3schools.in/demo/custom-lightbox/
clickid=more
waitForElementPresentcss=span.button1.close
verifyElementPresentcss=span.button1.close
clickcss=span.button1.close

In similar way you can verify element not present using selenium IDE.

3 comments:

  1. http://w3schools.in/demo/custom-lightbox/ is not present, so can u provide with latest example for Verify/WaitFor ElementPresent?

    ReplyDelete
  2. can you point me to information on how to handle event when either verifyElementPresent false or verifyElementNotPresent = True. How to continue script without failing

    ReplyDelete
  3. Can you point me to information on how to handle element when verifyElementPresent is false or verifyElementNotPresent is true. Looking for details on how to continue testing when either element is verified.

    ReplyDelete