2

I have a site https://master.nst.com.my/sports. There is advertisement pop up display randomly for certain menu options. There is no rules regard this. How to detect when there is pop up display then i just close the pop up.

https://drive.google.com/file/d/1FZMdu1Er_ny9issuzXC8MLdHU9q0-1tY/view?usp=sharing https://drive.google.com/file/d/1uqPDzPdKX4qrl_nSKeOsOz2kzj93bAjB/view?usp=sharing

nicholas
  • 2,581
  • 14
  • 66
  • 104

1 Answers1

0

First of all that site is absolutely awful. I used my non-ad-block browser to help you out and it embeds 50 to 70 cookies at a time.

Secondly, create a method that you put at the end (or beginning) of any navigation you do on the site. Look for the id "ad_position_box". If you see that, there is an adbox on screen. I don't know what language you're using, but something like:

int count = 0; //count 20 * 100 milliseconds is 2 seconds. Change this based on your browser speed.
while (findelements(xpath of your adbox).count() == 0 && count < 20){
   If you're in here, the adbox is NOT on screen. But now you need to loop a few times because you don't know how long it will take to show up.
Thread.sleep(100); //a sleep is permissible here because we literally have no existing element to wait for.
count++;
}

//Once you get out here, either you have an adbox or you don't.

if (findelements(xpath of your adbox).count() > 0){
  refresh the page.
}

I tried the escape key and that didn't do it. But if you simply refresh the page as soon as you see the "ad" element, it goes away.

Yes, this adds 2 seconds (or 5) to every page load you do. But you don't know if that element is there or not, and how long it may or may not take to load. This isn't a pretty solution, but it's not a pretty site to automate.

shaidyn
  • 21
  • 6