Tutorial

How to handle website notices if they appear

Click on an element if it appears. Ignore if not!

Robocorp

Most websites display a notice when you visit them the first time (cookies, privacy, newsletter subscription, other agreements). If your robot includes visiting a website, often dismissing the notices will be the first task you need to tell your robot to do.

Something you need to consider is that sometimes there is a slight delay before the notice is displayed. On some occasions, the notice might not display at all!

Selenium (RPA.Browser.Selenium)

The following robot will click on an element if it appears. If not, the robot will ignore it:

The wait-and-click-or-ignore logic is implemented in the custom Click element if it appears keyword:

The default logging behavior is to embed a screenshot in the log when a browser keyword fails. In this case, we don't want the screenshot (the screenshots might be big and take unnecessary cloud storage space). We accept the occasional failure as a normal condition (sometimes the notice is there, sometimes not 🤷‍♀️).

The Mute Run On Failure keyword (from the RPA.RobotLogListener library) prevents the Click Element When Visible keyword (from the RPA.Browser.Selenium library) from generating a screenshot on failure.

The Click Element When Visible keyword waits for the element to become visible before clicking on it. If the element does not appear, the error caused by the non-matching locator is ignored by the Run Keyword And Ignore Error keyword (Robot Framework built-in library):

With those notices out of the way, your robot can start interacting with the website!

Playwright (RPA.Browser.Playwright)