I'm using Selenium IDE for Chrome and I'm trying to click somewhere only if a specific element doesn't exist.

If I only wanted to do that, I can do it with an assert:

assert element not present    css=.something
click                         css=.button

However, this is part of a larger script and I want to continue with the rest of the script regardless of whether the element exists.

So I want to do something more like:

if          {something which means roughly "assert element not present"}
   click    css=.button

Is this possible? How do I do this?

3 Answers 3


You can do this with if/endif of the kantu selenium ide:

verifyElementPresent (locator)
if | !{!statusOK}
 Click (...)
Script continues... 

=> The "trick" here is to use !statusOK to check in the status of the last command. ${!statusOK} here it will be true if the element is found by verifyElementPresent. The ! in front of the variable inverts this. So the Click is reached when the element is not found.


Check out my update to an older Stack Overflow question on using Selenium 3 using store xpath count and if...end to execute code.

The basic idea:

store xpath count | css=.something | how_many_somethings if | ${how_many_somethings} < 1 ...magic stuff... end

The other question has a screen shot and link to a full article.



try {
       //Do nothing
} catch (ElementNotFound) { click }

If no JavaScript wait is necessary:

if( ! element.IsVisible()) click;

//Continue with your life ...

  • 1
    The question is about Selenium-IDE
    – Alexey R.
    Commented Oct 8, 2018 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.