title: Popup window on youtube - how to close with selenium
body: <p>Could you please help me with one issue?  I  have got a problem with Selenium and popup windows with agreements on youtube.<br />
  When first window is jumped - Selenium close this  window, but if I want to close second window/frame, selenium doesn't work. Could you please help?
  The part of code attached below:</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.by import By
  from selenium.webdriver.support import expected_conditions as EC
  from selenium.webdriver.support.wait import WebDriverWait
  from time import sleep
  class YoutubeSearcher:
      def __init__(self, search):
          self.search = search
      def open_url(self) -&gt; None:
          driver = webdriver.Chrome()
          driver.get('https://www.youtube.com/')
          try:
              WebDriverWait(driver, 5).until(
                  EC.element_to_be_clickable((By.XPATH, '/html/body/ytd-app/ytd-popup-container/paper-dialog/yt-upsell-dialog-renderer/div/div[3]/div[1]/yt-button-renderer/a/paper-button/yt-formatted-string'))).click()
          except:
              print(&quot;no alert to accept&quot;)
          WebDriverWait(driver, 10).until(
              EC.element_to_be_clickable((By.XPATH, '//*[@id=&quot;yDmH0d&quot;]/c-wiz/div[2]/div/div/div/div/div[2]/form'))).click()
          search = driver.find_element_by_id(&quot;search&quot;)
          search.clear()
          search.send_keys(self.search)
          submit_button = driver.find_element_by_id(&quot;search-icon-legacy&quot;)
          submit_button.click()
  </code></pre>