Unable to click Button on Popup Window (with about:blank) with Python Selenium

Issue

I am trying to click a button using Python Selenium that appears on a Popup or Window (where the url is shown as about:blank) which shows up at some point in the process, and I need to click Yes/No on this Window. However, I cannot do so even if I switch to the new window. Using driver.window_handles, it seems to me this Popup is a Window and not an iframe as I can switch to it with driver.switch_to.window(). However, I cannot click the button Yes/No. Inspecting the "Yes" in the HTML code of the Popup/Window, here is how I try to click it in my code. driver.find_element(By.CSS_SELECTOR,'div[onclick="javascript:self.opener.document.forms[0].operation.value = document.resultForm.operation.value;window.close();self.opener.showProgressAndSubmit();"]').click()

What happens when I try this is that the code just freezes, and nothing happens even in Debugging mode.

When I manually do these steps (and not with Selenium), even a simple click of Enter does the job for me. However, in Selenium Enter also does not work.

What am I doing wrong here?

P.S: The code that generates the Yes/No Box is <div onclick="document.inqPrinPage.operation.value='submit'; document.inqPrinPage.submit();" class="Button">Submit</div>

Here is the Full HTML Code of the Popup Window.

<html><head>
  <title>Warning!</title>
  <meta http-equiv="Content-Type" content="text/html" ;="" charset="iso-8859-1">
  <style type="text/css"></style>
  <link rel="stylesheet" href="webapp/styles/common.css">
  <script type="text/javascript" language="JavaScript">
  <!--
  var defaultAction;
      function catchkey() { 
           if (event.keyCode == 13) { 
               eval(defaultAction); 
           } 
      } 
  // --> 
  </script>
  </head>
  <body onkeypress="catchkey()">
    <form name="resultForm">
      <input type="hidden" name="operation" value="confirmSubmit"> 
      <table class="Text" border="0" width="100%">
        <tbody><tr height="50">
          <td width="50%" colspan="2" align="center" class="PageTitle">
                Warning!</td></tr>
        <tr class="Text">
          <td width="50%" colspan="2" align="left">A worldwide search will be performed. <br>Do you wish to continue? <p>Select Yes to submit the inquiry. <br>Select No to search specific regions and/or countries.
          </p><p></p></td></tr>
        <tr height="50">
           <script type="text/javascript" language="JavaScript">  defaultAction = 'javascript:self.opener.document.forms[0].operation.value = document.resultForm.operation.value;window.close();self.opener.showProgressAndSubmit();'</script>
        <td width="50%" align="center">
             <table cellpadding="0" cellspacing="0" border="0">
               <tbody><tr>
                 <td height="16"><img height="17" border="0" src="webapp/images/roundedLeftCap.jpg"></td>
                 <td valign="middle" height="14"><div onclick="javascript:self.opener.document.forms[0].operation.value = document.resultForm.operation.value;window.close();self.opener.showProgressAndSubmit();" class="Button"> &nbsp;Yes</div></td>
                 <td height="16"><img height="17" border="0" src="webapp/images/roundedRightCap.jpg"></td>
               </tr></tbody></table></td>
        <td width="50%" align="center">
             <table cellpadding="0" cellspacing="0" border="0">
               <tbody><tr>
                 <td height="16"><img height="17" border="0" src="webapp/images/roundedLeftCap.jpg"></td>
                 <td valign="middle" height="14"><div onclick="javascript:window.close();" class="Button"> &nbsp;No</div></td>
                 <td height="16"><img height="17" border="0" src="webapp/images/roundedRightCap.jpg"></td>
               </tr></tbody></table></td>
        </tr>
    </tbody></table>
    </form>
  

</body></html>

Solution

As per @aaron’s suggestion, simply adding options.page_load_strategy = 'none' to the beginning (and then obviously properly calibrating the wait times for the other elements – for me WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(n)) was sufficient) did the trick to resolve the issue with freezing when interacting with the about:blank popup window.

Answered By – Dimitri

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published