How to detect an element on a page that appears randomly?

Hello to all!
I have a problem. I want to test the page https://the-internet.herokuapp.com/disappearing_elements with codeceptjs. The gallery item appears randomly. I thought to implement it like this:
If I see an element, then click, if not, then reload the page and, if I see an element, click.
I cannot go through the cycle with the tools that I have too.
Tell me how you can implement this task. I already thought maybe I can use webdriverio tools

I would write a custom helper like this. But yes, I think it might be better to break the abstraction and use webdriver directly.

class ReloadHelper extends Helper {
   async reloadForElement(css, maxTimes) {
      const browser = this.helpers.WebDriver.browser
      // use the webdriver browser to find the element and reload the page if it's not found
   }
}

Then in your tests you can do this:

I.reloadForElement('#random-element', 3)