How to verify element NOT present?

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

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?

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.

I have the same issue but the point where I want to implement this is already inside of an if/endif where this piece of code only executes when the value of a field read in from a .csv file equals a certain value and kantu fails and says that nested ifs are not allowed.

i.e. On a payment form ACH is only visible if the address is United States so the code checks if columnX of the .csv row = United States and verifies ACH present and a separate if checks if columnX != to United States and I want to verify that ACH is not present but it won’t allow me to nest this if inside of the other if.

but it won’t allow me to nest this if inside of the other if.

The workaround here is to use Label… GotoIF for outer IF or while loop. Then you can use IF… inside.

Btw, nested while/Ifs and verifyNOTpresent will be available in a few weeks.

1 Like

“… verifyNOTpresent will be available in a few weeks.”

Any news?

Greetings

I am not sure since when, but “verifyElementNotPresent” is available in the command dropdown meanwhile :slight_smile:

Nested while/Ifs are meanwhile supported, too.

1 Like

Ohh … thx for sharing …

i´m on the latest? stable paid version (5.0.4) and there is “verifyXXXnotpresent” still not available …

I could confirm “verifyXXXnotpresent” on the free version 5.1.9 .

greetings

verifyElementNotPresent is available meanwhile. I tested on V5.2.3 Enterprise Edition.

Test:

{
  "Name": "verifyElementNotPresent",
  "CreationDate": "2019-9-23",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.steelmint.com/crc-prices-global",
      "Value": ""
    },
    {
      "Command": "verifyElementPresent",
      "Target": "xpath=//*[@id=\"tblPrices_E_I_\"]/tbody/tr[1]/td[1]",
      "Value": ""
    },
    {
      "Command": "verifyElementNotPresent",
      "Target": "xpath=//*[@id=\"xxxxxtblPrices_E_I_\"]/tbody/tr[1]/td[1]",
      "Value": ""
    }
  ]
}