Cookie pop up locator does not work


I am trying to set-up a robot to login to my account to simply download the monthly invoices.
The problem is that my robot is blocked by the cookie pop-up because it can’t locate it despite getting the css locator with inspect function or trying using the xpath approach.
(as per How to find user interface elements using locators in web applications | Robocorp documentation)

Could someone try to help me with this ?

Here is the code:
*** Settings ***
Documentation Login to EE website, download the monthly invoice and send it to the accountant

Library RPA.Browser.Selenium auto_close=${FALSE}
Library RPA.Robocorp.Vault

*** Tasks ***
Get Latest bill from EE
Open Available Browser
Sleep 3s
Click css=body > div:nth-child(16) > div.mainContent > div > div.pdynamicbutton >

Thank you

Note: I have checked that the selector is working in the console, so I am quite puzzled.

Also I know that it is supposed to be better to use id or name for the locator strategy but it seems that button does not have any of these => is my understanding correct?

Without javascript hacks, you can’t click on elements that are hidden or blocked behind other elements (at least with Selenium) … You should dismiss the cookie dialog first.

Thank you for your answer but I don’t understand. my problem is all about that cookie dialog box and I have identified the locator for that dialog box using How to find user interface elements using locators in web applications

The locator of “accept all cookies” is “body > div:nth-child(16) > div.mainContent > div > div.pdynamicbutton >”

But it does not work when I use it
=> Click element css:body > div:nth-child(16) > div.mainContent > div > div.pdynamicbutton >
I have tried click button, click element, click link. Nothing is working and I always get the same error: “Element with locator xxxx not found”

Any thought?

Few thoughts.

  1. Cookie dialog is inside iframe, so if you are using SeleniumLibrary you have to switch to iframe using Select Frame keyword, click button and than unselect iframe using Unselect Frame keyword.
  2. Such cookie locators tend load slowly and in you code I see hardcoded sleep value. So occasionally you will try to perform action before content is loaded.

Thank you for your guidance.
I have tried to select the iframe but it does not work either. I get the error that the element is not found. Although I have selected the iframe and copy the selector for it

Open EE website
Sleep 5s
Select Frame pop-frame06894139545708449
Click button css: body > div:nth-child(16) > div.mainContent > div > div.pdynamicbutton >

Id of you iframe is different each time you open the page. You need different locator, for instance xpath=//iframe[contains(@id, "pop-frame")].

1 Like

Hello Aleh,

Ok, I get that. Now, eventhough I manage to select the frame, I still get an error saying that the button with locator xxxxx cannot be found.
Could it be due to the fact that there are other iframes inside the main iframe? And I would need to select one of those iframe after the main one?

current code:
Open EE website
Wait Until Element Is Visible xpath=//iframe
Select Frame xpath=//iframe[contains(@id, “pop-frame”)]
Wait And Click Button css= body > div:nth-child(16) > div.mainContent > div > div.pdynamicbutton >

If you simplify this line


Wait And Click Button css=


Wait And Click Button css= div.pdynamicbutton >

Does it click the element you want?

I’ve not used the CSS selector method much but I would expect that like xpath the simpler (less strict) your selection criteria the more reliable your script will be.

As a general rule of thumb you want to use the minimum number of selectors or elements you can to identify your object because the page structure is likely to change over the development lifecycle (or even sometimes based on form selection), the more of the html structure you are using to find the element you want to act on the more chance for script failure and the script maintenance you’ll need.


Yes, I have tried shorter version of the selectors but it does not work either

It is as if I am still not in the right frame

Ok, the part where I would expect you are having issues is div:nth-child(16)

Is it still the 16th div and not now the 13th, 15th, 17th, you get the idea?

If it is still the 16th div the was something else (dynamic content?) added into the html structure that wasn’t there when you constructed the path?

Also do you need to use the css selectors? I would have used xpath something like this: //a[text()="Accept all cookies"]

or even the text selector text= Accept all cookies


I have already tried
click text= Accept all cookies
but it does not work either.

I have done xpath too but it does not work either and I have tried with the shorter selector or div.pdynamicbutton >
Nothing is working. I am really puzzled with this one

Now, I have tried your suggestion with the xpath=//a[text … ] and it does not work either

iframe[contains(@title,TrustArc Cookie Consent Manager”])[1]
Use Sleep 2 before before visibility

I think I just noticed your problem, you are using Click Button on a hyperlink, you should be using Click Link or Click Element

A html <a> tag is a hyperlink not a button, in your case its just styled to look like a button with some CSS

Thank you but that does not work. I think it is because there is no title property for the iframes

InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //iframe[contains(@title,"TrustArc Cookie Consent Manager”)] because of the following error:

SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘//iframe[contains(@title,"TrustArc Cookie Consent Manager”)]’ is not a valid XPath expression.
(Session info: chrome=104.0.5112.101)

I have tried these before as well and it does not work either (and I have tested now with your latest thought about robust locator)

This could be a page loading issue, try waiting before the click, e.g.

    Wait Until Element Is Visible    //a[text()="Accept all cookies"]
    Click Element    //a[text()="Accept all cookies"]


    Wait Until Element Is Visible    css=
    Click Element    css=

Also be careful with

Wait Until Element Is Visible xpath=//iframe
Select Frame xpath=//iframe[contains(@id, “pop-frame”)]

because if there is another iframe loaded before the “pop-frame” you might get an error with Select Frame if the frame hasn’t loaded yet, I would suggest you do this:

Wait Until Element Is Visible xpath=//iframe[contains(@id, “pop-frame”)]
Select Frame xpath=//iframe[contains(@id, “pop-frame”)]


Ok, I have found the solution. It is a combination of Ajay and Dave answers.
After selecting the frame, I need the robot to wait because the frame appears much faster than the link. Then after sleeping for 2s, I need to click Element or click Link.

So, integrating selector optimisation, the program has become like this (and it does work now!):

Open Available Browser
Wait Until Element Is Visible    xpath=//iframe
Select Frame    xpath=//iframe[contains(@id, "pop-frame")]
Wait Until Element Is Visible    xpath=//a[text()="Accept all cookies"]
Click Element    xpath=//a[text()="Accept all cookies"]
Unselect Frame

Thank you for continuous support!