title: popup alert - search loop
body: <p>I am a beginner so the question may be strange :)</p>
  <p>I want to test the Main Menu of the website &quot;https://tvn24.pl/&quot;</p>
  <p>I am looking for elements, I put them into the list and then iterating through it opening each page found - Works fine</p>
  <p>Now step two:
  On only two pages(<a href="https://kontakt24.tvn24.pl/" rel="nofollow noreferrer">https://kontakt24.tvn24.pl/</a> and <a href="https://tvn24.pl/" rel="nofollow noreferrer">https://tvn24.pl/</a> ) a window pops up in which you should click the &quot;consent&quot; button.</p>
  <p>It is a completely different confirmation dialog for each page (different xpath, Id, etc.)</p>
  <p>I would like to write functions (loops)
  Which will be checked for 5 seconds if the window appeared, if so, click the accept button.
  I would like this function to check both cases of &quot;alert&quot;.
  If a window &quot;A&quot; pops up - Click Accept - end of function
  If a &quot;B&quot; window pops up instead of &quot;A&quot; - Click Accept - end of function
  If no window pops up, do nothing.</p>
  <p>Attention :</p>
  <ol>
  <li>These popups are elements that cover the entire page.</li>
  <li>These are not allerts or frames - ordinary &quot;DIV&quot; so you can't use swith to alert or frame</li>
  <li>I know, I can also use a try:</li>
  </ol>
  <p>Any hints?
  Loop while with if, elif?</p>
  <p>I tried something like this but it doesn't work</p>
  <pre><code>def alert_accept_if_with_Wait_V2(driver):
      V1_alert_window_Id = &quot;onetrust-banner-sdk&quot;
      V1_accept_button_Id = 'onetrust-accept-btn-handler'
  
      V2_alert_frame_Id = &quot;rodoLayer&quot;
      V2_accept_button_Xpath = './/*[@id=&quot;rodoLayer&quot;]//a[@class=&quot;rodoFooterBtnAccept&quot;]'
  
      wait = WebDriverWait(driver, timeout=5, poll_frequency=0.5)
  
      if wait.until(ec.presence_of_element_located((By.ID, V1_alert_window_Id))):
          wait.until(ec.element_to_be_clickable((By.ID, V1_accept_button_Id))).click()
          print(f&quot;On page {driver.current_url} onetrust alert accepted&quot;)
      elif wait.until(ec.presence_of_element_located((By.ID, V2_alert_frame_Id))):
          wait.until(ec.element_to_be_clickable((By.ID, V2_accept_button_Xpath))).click()
          print(f&quot;On page {driver.current_url} old alert accepted&quot;)
      else:
          print(f&quot;On page {driver.current_url} no alert appeared &quot;)
  </code></pre>
  <p>Another :</p>
  <pre><code>def alert_accept_if_with_Wait_V1(driver, max_seconds_to_wait=5):
  
  V1 = './/*[@id=&quot;onetrust-accept-btn-handler&quot;] '
  V2 = './/*[@id=&quot;rodoLayer&quot;]//a[@class=&quot;rodoFooterBtnAccept&quot;]'
  
  seconds = 0
  while range(max_seconds_to_wait):
      if driver.find_element_by_xpath(V1 or V2):
          driver.find_element_by_xpath(V1 or V2).click()
          return False
      else:
          seconds += 1
      time.sleep(1)
  else:
      print(f&quot;On page {driver.current_url} no alert appeared &quot;)
  </code></pre>