How to click 'close' button in the popup screeen

Hi, I’m just following the instruction from Jani Youtube at the page of “Development Guide”.
When I run all the flows directly from browser myself, it works well.
But when I run tasks.robot (same robot as Jani’s) working on the flows, AD popup shows up.
To click ‘close’ button in the popup screen, first I looked into the source in the DevTools of Chrome and tried to click the button like below but they don’t work.
# Click Button When Visible //[@id=“dismiss-button”]
# Click Button //
# Click Element When Visible //*[@id=“dismiss-button”]
# Click Element When Visible css:#dismiss-button
# Click Element When Visible id:dismiss-button

Why does popup show up only when I run the tasks.robot?
How can tasks.robot click the button in the popup screen?

I’d appreciate it if you hep me with this.

Hello @hwaslee and welcome :wave:t3: It looks like adds are inside iframe so you need to select those first. Reason you are not seeing them with robot run is that robot uses clean browser without your user profile. I tried with keyword below and added Run Keyword And Ignore Error Handle Ad
to Get lyrics Hope it helps :robot:

Handle Ad
    Wait Until Page Contains Element    css=#aswift_1
    Select Frame    css=#aswift_1
    Select Frame    css=#ad_iframe
    Click Element    css=#dismiss-button
    Unselect Frame
    Unselect Frame

As this video is almost 2 years old, I noticed that you need some more modifications to code. But I leave that for you :smiley:

Thanks, linkraivo
With your code, my code works well from end to end.
I need to elaborate on the code regarding what and how to solve if this kind of problem happens again.

Another problem is sometimes the ad popup has ‘close’ button but sometimes not.
If there is no ‘close’ button, it has ‘X’ button at the upper right corner instead.
Is there any way to solve this conditional case?
Do I have to do trial-error method?

I appreciate your help.

Selenium has keywords to check if element is on current page. And then you can use conditional flow based on that.

Thanks for the reply, Linkraivo
I can see many keywords in Selenium library.