How to verify element NOT present?


#1

Hello.
I didn’t find any command to check that element disappeared.
Are there any known workarounds?
Thanks in forward.


#2

Good question. You can invert every assert… or verify… command by checking on its result with !statusOK and then use throwError if the command was successful.

Note that if you use assert… or a normal command like ClickAt you also need to do a store | true | !errorignore so the macro continues despite the error. But with verify… commands this is not required, as they only trigger warnings, but not errors.

=> verifyElementNotPresent example:

In the test case, I also reduced the time Kantu waits for the element to appear to 2 seconds by storing this value in !timeout_wait.

{
  "CreationDate": "2018-8-3",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://forum.a9t9.com/t/how-to-verify-element-not-present/365",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "2",
      "Value": "!timeout_wait"
    },
    {
      "Command": "verifyElementPresent",
      "Target": "//*[@id=\"post_1\"]/div/div[2]/div[1]/div[2]/a/span",
      "Value": ""
    },
    {
      "Command": "if",
      "Target": "${!statusOK}",
      "Value": ""
    },
    {
      "Command": "throwError",
      "Target": "The element _is_ there, but it should not be",
      "Value": ""
    },
    {
      "Command": "endif",
      "Target": "",
      "Value": ""
    }
  ]
}

Screenshot:

=> Does this solution work for you?


#3

Yep, this works, though it seems to be much hustle around it…
Is it planned to make selenium-like *NotPresent commands?
UPD: i encountered somewhere in commands faq, that there is an idea to reduce commands and use IF instead of them. I understood the concept. Thanks, may be closed.