title: How to close a pop up window in Selenium?
body: <p>I am trying to close a pop up window which is not allowing my code to execute further. But I am unable to do that. There is a a pop up window which says 'Free pound 5 voucher' which is not getting closed.</p>
  
  <p>Below is my code. Please check and suggest.</p>
  
  <pre><code>public class Alldetails {
      WebDriver driver;
      public List&lt;String&gt; links1 = new ArrayList&lt;String&gt;();
  
      @BeforeTest
      public void beforeTest() {
          System.setProperty("webdriver.chrome.driver", "C:\\Pankaj\\chromedriver.exe");
          driver = new ChromeDriver();
          // driver = new FirefoxDriver();
          driver.manage().window().maximize();
      }
  
      @Test
      public void f() {
          driver.get("http://www.debenhams.com/kids/t-shirts-tops/boys");
          driver.findElement(
                  By.xpath(".//*[@id='dijit__WidgetsInTemplateMixin_0']/div/div[1]/button"))
                  .click();
  
          WebElement a = driver.findElement(By.className("products_count"));
          String product_count = a.getText();
          Integer x = Integer.valueOf(product_count);
          System.out.println(x);
          for (int i = 1; i &lt; (x / 60) + 1; i++) {
              driver.get("http://www.debenhams.com/kids/t-shirts-tops/boys" + "?pn=" + i);
  
              List&lt;WebElement&gt; links = driver
                      .findElements(By.className("item_container").tagName("a"));
              for (WebElement abcx : links) {
                  String ax = abcx.getAttribute("href");
                  // if(!links1.contains(ax))
                  links1.add(ax);
              }
  
              for (String b : links1) {
                  if (b.contains("/webapp/wcs/stores/servlet/prod"))
                      System.out.println(b);
              }
          }
      }
  
      @AfterTest
      public void afterTest() {
      }
  }
  </code></pre>