How to verify that element doesn't exist

Hello, I have problem with validating that element is not present on the page. This seems to me like a basic thing, but I am not able to verify it.

Example: I want to test filtering on our web and I want to verify that exact record is not present.
I tried to use “Get Element States id=record1 contains hidden” but it fails as it doesnt finds it at all
([ FAIL ] Elements states ‘[‘detached’]’ (list) should contain ‘[‘visible’]’ (list))
I also tried to use “Run Keyword And Expect Error” but it always pause my execution and wants me to press Enter to continue.

Please can you advise me on how to aproach this?

Hi Pavel,

Have you tried detached?

Dave.

From the documentation:

1 Like

Get Element Count yourSelector == 0

https://marketsquare.github.io/robotframework-browser/Browser.html#Get%20Element%20Count

2 Likes

Thanks a lot :heart: I am new in this and I was pretty sceptical about writing on forum, but theese fast and helpful asnswers really brightened my day. Love you guys :)))

1 Like

how to check a text is absent in current page
ex in selenium library
Page should not contains tex
or Current frame should not contains tex
Thank you

Hi Hbib,

Not sure if there’s a better way but you can do this:

  • Get Element combined with an xpath like //*[contains(text(), "text your searching for")] should give you the element that contains that text if it exists and an error if not
  • Combine that step above with Run Keyword And Expect Error and you should get a pass if the text is not there and an error if it is.

Hopefully that helps,

Dave.

Thank you a lot

1 Like

I did this but if the element is not there it takes time untill it returns and unfortunatley I cannot pass timeout to it.

Hi Odai,

If you need to temporary have a short timeout, follow the example in Set Browser Timeout

  • Set Browser Timeout to a short value and save the original timeout value
  • get element
  • Set Browser Timeout back to the original timeout value

Dave.

1 Like