2017-05-13

Deal with Annoying Popup New Tabs in Selenium

When I was trying to scraping a website using selenium webdriver, everytime I navigate to new url, a third party annoying advertisement page opened which I cannot block it out.

So I found out WindowHandler if Selenium which quite userful.

Simpley here is how I make it.


C#
public static void RemoveAdd()
{

    if (driver.WindowHandles.Count() > 1)
    {
        do
        {
         driver.SwitchTo().Window(driver.WindowHandles.Last());   
         driver.Close();   
         driver.SwitchTo().Window(driver.WindowHandles.Last());         
         } while (driver.WindowHandles.Count() > 1)         
     }

}





No comments:

Post a Comment

Setup VNC on Ubuntu 20.04

  sudo apt update sudo apt install xfce4 xfce4-goodies sudo apt install tigervnc-standalone-server sudo apt install tightvncserver vncserver...