Переключение на новое окно иногда приводит к появлению страницы ошибки в новом окне, когда родительское окно работает в фоновом режиме - PullRequest
0 голосов
/ 04 декабря 2018

введите описание изображения здесь

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0070)http://ussbyintv8057.acetst.com/Enterprise_CRS/CAT06/NewQuote/ast.aspx -->
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
  <title>Aboveground Storage Tank</title>
  <meta name="vs_snapToGrid" content="False">
  <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  <link rel="stylesheet" type="text/css" href="./Aboveground Storage Tank_files/ACE.css">
  <script language="JavaScript" src="./Aboveground Storage Tank_files/Calendar.js.download"></script>
  <script language="javascript" src="./Aboveground Storage Tank_files/CommonFunctions.js.download">
  </script>
  <script language="javascript">
    function Validate_Page() {
      var err_msg = ""

      if (document.all.txtASTID.value.length < 1) {
        err_msg = "AST ID required;"
      }

      if (document.all.txtDate.value.length < 1) {
        err_msg = err_msg + "Installation Date required.;"
      } else {
        if (!isDate(document.all.txtDate.value)) {
          err_msg = err_msg + "Installation Date must contain a valid date.;"
        }
      }
      if (document.getElementById("txtRetroDate").style.visibility != 'hidden') {
        if (document.getElementById("txtRetroDate").value == "") {
          err_msg = err_msg + "Retroactive Date required.;"
        } else if (!isDate(document.getElementById("txtRetroDate").value)) {
          err_msg = err_msg + "Retroactive Date must contain a valid date.;"
        }
        //CHANGE START QC ID 11096 - Release 3.8- DONE BY N9V333
        else if (document.all.txtDate.value.length > 1 && isDate(document.all.txtDate.value)) {
          if (new Date(document.getElementById("txtRetroDate").value) < new Date(document.getElementById("txtDate").value))
            err_msg = err_msg + "Retroactive date cannot be prior to the tank installation date. Please correct;"
        }
        //CHANGE END QC ID 11096 - Release 3.8- DONE BY N9V333
      }
      if (!document.all.radlASTSecContainment_0.checked && !document.all.radlASTSecContainment_1.checked && !document.all.radlASTSecContainment_2.checked) {
        err_msg = err_msg + "AST's Secondary Containment required.;"
      }

      if (!document.all.Radio1.checked && !document.all.Radio2.checked) {
        err_msg = err_msg + "Please answer question concerning Piping Secondary Containment (Y/N);";
      }

      if (!document.all.Radio3.checked && !document.all.Radio4.checked) {
        err_msg = err_msg + "Please answer question concerning Automatic Overfill / Spill Protection ....:  (Y/N);";
      }


      if (document.all.txtGallons.value.length < 1) {
        err_msg = err_msg + "AST Capacity entry required.;"
      } else {
        if (!isValidNumeric(document.all.txtGallons.value)) {
          err_msg = err_msg + "AST Capacity must be numeric.;"
        } else {
          //Changes made on 2009-05-14 start
          if (document.all.txtGallons.value > 49999 && document.getElementById("hdnIsUnderwriter").value != "1")
          //Changes made on 2009-05-14 end
          {
            err_msg = err_msg + "AST Capacity cannot exceed 49,999.;"
          }
        }

      }

      if (document.all.selContents.value == -1) {
        err_msg = err_msg + "Tank Contents selection required.;"
      }

      // CHANGE START: RELEASE 3.7.1 TURNING ON FL; QCID:9000 DONE BY: N9V333;
      //debugger;
      if (('Underwriter' == 'Underwriter')) {
        if (('UW' == 'BK')) {
          if (document.all.hdnState.value != "FL" && document.all.hdnRenVer.value == 1) {
            //debugger;
            if (document.all.txtRetroDate.value != "") {
              var mindate = new Date(Date.parse("01/01/2010"));
              var retro = new Date(Date.parse(document.all.txtRetroDate.value));
              if (retro < mindate) {
                err_msg = err_msg + "Retroactive Date cannot be prior to 2010."
              }
            }
          }
        }

      } else {
        if (document.all.hdnRenVer.value == 1) {
          //debugger;
          if (document.all.txtRetroDate.value != "") {
            var mindate = new Date(Date.parse("01/01/2010"));
            var retro = new Date(Date.parse(document.all.txtRetroDate.value));
            if (retro < mindate) {
              err_msg = err_msg + "Retroactive Date cannot be prior to 2010."
            }
          }
        }
      }
      //CHANGE START: RELEASE 3.7.1 TURNING ON FL; QCID:9000 DONE BY: N9V333;

      // 2.7b retro start
      if ((document.all.hdn_appstate.value == 1 && document.all.hdnState.value != "FL") || (document.all.hdn_appstate.value == 1 && document.all.hdnState.value == "FL" && document.all.hdnRenVer.value != 1)) {
        if (document.all.txtRetroDate.value != "") {
          //Changes start for CRS-99
          if ('Underwriter' == 'Broker') {
            //Changes end for CRS-99  
            var diff_eff = new Date(Date.parse(document.all.hdnRetro.value));
            var diff = new Date(Date.parse(document.all.txtRetroDate.value));
            var year = (diff_eff.getFullYear()) - (diff.getFullYear());
            if (year > 10) {
              err_msg = err_msg + "Retroactive Date cannot be more than 10 years;"
            }
            //Changes start for CRS-99
          }
          //Changes end for CRS-99 

          //alert(diff_eff.getFullYear());
          //alert(year);
          //return false;
        }
      }
      // 2.7b retro end



      //hawaii start
      if (document.all.hdnState.value == "HI" || document.all.hdnState.value == "KS") {
        if (!document.all.Radio5.checked && !document.all.Radio6.checked) {
          err_msg = err_msg + "Please answer question concerning AutomaticTankGauging ....:  (Y/N);";
        }
      }
      //hawaii end

      if (err_msg.length > 0) {
        //call the window to display the err_msg
        //stop the user from going forward....until errors are corrected
        //alert(err_msg)
        //ie8
        //window.open('../ErrorHandler/ErrorDisplay.aspx?error='+err_msg,'','menubar=no,status=yes,toolbar=no,height=' + (window.screen.availheight * .40) + ',width=' + (window.screen.availwidth * .60) + ',top=' + (window.screen.availheight * .20) + ",left=" +  + (window.screen.availwidth * .20) );
        window.open('../ErrorHandler/ErrorDisplay.aspx?error=' + err_msg, '', 'menubar=no,status=yes,toolbar=no,height=296,width=818,top=148,left=273');
        //ie8
        return false;
      }



    }
  </script>
</head>

<body language="javascript" ms_positioning="GridLayout" style="background-color: #f7f3f7">
  <form name="ASTF" method="post" action="http://ussbyintv8057.acetst.com/Enterprise_CRS/CAT06/NewQuote/ast.aspx" id="ASTF">
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="">
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="">
    <input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="">
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="GbJqOk+UZo3hc6eziOSe1TWs1YFJe8diotc3h7bt+nAPjwWT/5CejnvP3/CGLxHf5Nowh+weD3cK8ylbUVK8f+oSrZ8S196kSuvJHdZOmG1X7c/pNJcNEgo2UjVKYw9+jQWXgzXEBBjN1jfJC0ABAq6n4IpAwKaiQLBaXlFd7vsvy1ALlzBvCsWIwYHbYNfdsW0txHFS058RT3fmRjt8jxEC0xzFl+Z4loM2X1wuj7+QTqmfPESdZKgpcR89IYPVcIrOuQghc2v0tFsnniHjIaGu5JdkDr3Dk7cU79UPruFYwA+uh3EHKTc/qQKxw1SjIslHDdjE92hT9BuJto4R1MQGn96kT5NDkeRHMm7/n59W+G2g+V+4qV2gwJtGlF3J60p4uHkgngib7Ss05EyUZ8E8KwWN16FRKhtagYx9s3qVBg0+2ruvMiD6eQxa0NO2+uCRSltNXrZ3kXHoAGRInl0J7Mu9eP2CxPolwu8QHLW6VEyRQ3DB5gRrfrswxmBKfFrAQnW/WAQvJLl5kWdOJd+webpWoPxX0YOUiql/d/mujrHO++J842p//K+Dgx9Ve9LdllBnPSujeMPNflnsQmIH4Tibx8Oj9+nlC6EYCqTS0sW5dSIqlPnjsb7TnEy2kG+Yik1O4S+pkHWdLGf0QQo1xEkXKddQMBJMLWc4nt/71x9bzpxfPOwn7DHRGcLdgW9sXg1Q8iGyP0s/Tzdb0X0ZQfsMVYDvaAqmAKGq3LBjck6Vo/WxCJ+Dw8LBxIUOuHYjOr7qxkBwXpu8G1dsMEKdnx2/D2zHo6gI+Xp/C6SpquAOWBBExbnvRN7INwQWAJAkHLFUE0UMjXNBYBMAWAcHgD3vlbhM1AWYH40CNL6pZsPBvdefrIc+Q1apSFo4S6DzZSWLmO5zKNM5OGB27lL0JwWSPHfjBd/bfQ==">

    <script type="text/javascript">
      <!--
      var theForm = document.forms['ASTF'];
      if (!theForm) {
        theForm = document.ASTF;
      }

      function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
          theForm.__EVENTTARGET.value = eventTarget;
          theForm.__EVENTARGUMENT.value = eventArgument;
          theForm.submit();
        }
      }
      // -->
    </script>


    <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="431C18A6">
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="L8p4Ezi1hY1zmMsLghx4ZJ0i41/0K2tDT8Pa/1Lp5CGgl+/UgcpG1SQiGlcR4T/nBBKkPzRgWCLAXoFbjhOt5C0ydoSAyideL5w5VBPeR5hDQgxdMA+fG/l1Q+Sm5KLNKAyOKVyoHK/HzvHKW86894W4zruodHI5BJQbp1LWrtpBdgay9znmOa3q0PvT94XnT6jc/lQ1lubpSj0UD19DrlT0dFFoSkggeT8JkOR3fLGLei97UyeuMBG8vdUUvTQLZgZ9Hw5Cdjvipm3LFk56vggCyDMRJQUY8Sle85Sm96mqw70G9bo24MUFPP3ApGzvzQw9fsoZ/Gx/hQCU3gJBLdRFxDJmjHffN2ikkhQ4WEWYo+/JpYCSr/64mX17VwUwZ6TXpagqUadVbMTKM4ff0q8q2XVgB3baBRDqUwhDWzJ/9RJVJ0ckZ2mV4lN4vFmIz4MJ8PoRC65PYD0D9UiGtAikqcI1uO6nYSYhX9lQcCelAd0eZx7wggCfAokusbopVTQ+rp81x/EVwewjh730g7dKh+crGY2SUFVZNlHs4lbDyuWy32VxhTNvNJECFDz2+5McgNXe20nE3VWOzu8qGQnG9Qw/BzRMXHkqptmawZlCZYYQ7NtqaUOozq0FtjBprZbTHP4ydss9WLJX4qwQVt9qF+JWbrer+F1Qr4jEPmDE4z6BcqpRSglVUB8=">    &nbsp;
    <span id="Label1" class="StyledLabel" style="z-index: 100; position: absolute; top: 60px; left: 15px; bottom: 466px">Select AST:</span>
    <a onclick="setDateField(ASTF.txtRetroDate);top.newWin = window.open(&#39;../calendar.htm&#39;,&#39;cal&#39;,&#39;dependent=yes,width=60,height=220,screenX=100,screenY=150,left=550,top=233,titlebar=yes&#39;)" href="javascript:doNothing()">
      <img src="./Aboveground Storage Tank_files/calender_icon.png" id="Img3" style="z-index: 133; position: absolute; top: 137px; left: 385px; width: 22px;
            height: 20px" border="0" alt="Popup Calendar">
    </a>


    <span id="Label12" class="StyledLabel" style="z-index: 130; position: absolute; top: 299px; left: 241px">No</span>
    <span id="Label11" class="StyledLabel" style="z-index: 129; position: absolute; top: 279px; left: 240px">Yes</span>
    <span id="Label10" class="StyledLabel" style="z-index: 126; position: absolute; top: 226px; left: 241px; bottom: 310px;">Yes</span>


    <input value="Radio2" name="requirements2" type="radio" id="Radio3" style="z-index: 125; position: absolute; width: 13px; height: 20px; top: 282px;
        left: 230px" tabindex="110" checked="checked">
    <input value="Radio1" name="requirements2" type="radio" id="Radio4" style="z-index: 122; position: absolute; width: 13px; height: 20px; top: 302px;
        left: 230px" tabindex="110">
    <span id="Label9" class="StyledLabel" style="width:208px;z-index: 128; position: absolute; top: 277px; left: 16px">Automatic Overfill / Spill Protection and / or Electronic Leak Detection: </span>
    <span id="Label8" class="StyledLabel" style="z-index: 127; position: absolute; top: 247px; left: 241px">No</span>
    <input value="Radio2" name="requirements1" type="radio" id="Radio2" style="z-index: 124; position: absolute; top: 253px; left: 230px" tabindex="110">
    <input value="Radio1" name="requirements1" type="radio" id="Radio1" style="z-index: 123; position: absolute; top: 232px; left: 230px; bottom: 295px;" tabindex="110" checked="checked">
    <span id="Label6" class="StyledLabel" style="z-index: 121; position: absolute; top: 229px; left: 16px">Piping Secondary Containment:</span>

    <select name="selAST" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;selAST\&#39;,\&#39;\&#39;)&#39;, 0)" language="javascript" id="selAST" tabindex="10" class="StyledDropDown" style="width:177px;z-index: 101; position: absolute; top: 60px; left: 232px">
      <option value="-1">New AST</option>
      <option selected="selected" value="184253">test 1</option>

    </select>
    <span id="Label2" class="StyledLabel" style="z-index: 103; position: absolute; top: 108px; left: 15px">Installation Date:</span>
    <input name="txtDate" type="text" id="txtDate" style="z-index: 105; position: absolute; top: 110px; left: 232px; width: 145px" class="StyledText" tabindex="30" value="12/03/2018">
    <input name="txtRetroDate" type="text" id="txtRetroDate" style="z-index: 132; position: absolute; top: 136px; left: 232px; width: 145px" class="StyledText" tabindex="30" value="12/03/2018">
    <a onclick="setDateField(ASTF.txtDate);top.newWin = window.open(&#39;../calendar.htm&#39;,&#39;cal&#39;,&#39;dependent=yes,width=60,height=220,screenX=100,screenY=150,left=550,top=207,titlebar=yes&#39;)" href="javascript:doNothing()">
      <img src="./Aboveground Storage Tank_files/calender_icon.png" id="IMG1" style="z-index: 116; position: absolute; top: 110px; left: 385px; bottom: 416px;
            width: 22px; height: 20px" border="0" alt="Popup Calendar">
    </a>
    <span id="Label3" class="StyledLabel" style="z-index: 106; position: absolute; top: 160px; left: 16px">AST's Secondary Containment:</span>
    <table id="radlASTSecContainment" class="StyledLabel" border="0" style="width:230px;z-index: 107; position: absolute; top: 160px; left: 220px;
        font-weight: bold">
      <tbody>
        <tr>
          <td><input id="radlASTSecContainment_0" type="radio" name="radlASTSecContainment" value="IM" checked="checked" tabindex="40"><label for="radlASTSecContainment_0">Impermeable</label></td>
        </tr>
        <tr>
          <td><input id="radlASTSecContainment_1" type="radio" name="radlASTSecContainment" value="PR" tabindex="40"><label for="radlASTSecContainment_1">Permeable</label></td>
        </tr>
        <tr>
          <td><input id="radlASTSecContainment_2" type="radio" name="radlASTSecContainment" value="NA" tabindex="40"><label for="radlASTSecContainment_2">None</label></td>
        </tr>
      </tbody>
    </table>
    <span id="Label4" class="StyledLabel" style="z-index: 108; position: absolute; top: 388px; left: 17px">AST's Capacity Gallons:</span>
    <input name="txtGallons" type="text" value="12" maxlength="9" id="txtGallons" tabindex="50" class="StyledText" style="z-index: 109; position: absolute; top: 392px; left: 234px">
    <span id="Label5" class="StyledLabel" style="z-index: 110; position: absolute; top: 415px; left: 19px">Tank Contents:</span>
    <select name="selContents" id="selContents" tabindex="60" class="StyledDropDown" style="width:177px;z-index: 111; position: absolute; top: 420px; left: 234px">
      <option value="-1">Contents</option>
      <option value="Unleaded">Unleaded</option>
      <option selected="selected" value="Diesel">Diesel</option>
      <option value="Waste Oil">Waste Oil</option>
      <option value="Fuel Oil">Fuel Oil</option>
      <option value="Jet/Aviation">Jet/Aviation</option>
      <option value="Ethanol">Ethanol</option>
      <option value="Other">Other</option>

    </select>
    <input type="submit" name="btnAddTank" value="Add Additional AST" id="btnAddTank" tabindex="70" class="UsabilityButton" style="width:150px;z-index: 112; position: absolute; top: 470px; left: 20px; right: 805px;">
    <input type="submit" name="btnDeleteTank" value="Delete this AST" id="btnDeleteTank" tabindex="80" class="UsabilityButton" style="width:136px;z-index: 113; position: absolute; top: 470px; left: 272px">
    <input type="submit" name="btnSaveTank" value="Save" onclick="return Validate_Page();" language="javascript" id="btnSaveTank" tabindex="90" class="UsabilityButton" style="z-index: 114; position: absolute; top: 502px; left: 60px; width: 60px">
    <span id="lblASTID" class="StyledLabel" style="z-index: 118; position: absolute; top: 84px; left: 15px">AST's ID:</span>
    <input name="txtASTID" type="text" value="test 1" id="txtASTID" tabindex="20" class="StyledText" style="z-index: 119; position: absolute; top: 86px; left: 232px; bottom: 455px;">
    <input type="submit" name="btnDone" value="Done" onclick="return Validate_Page();" language="javascript" id="btnDone" tabindex="100" class="UsabilityButton" style="z-index: 120; position: absolute; top: 502px; left: 311px; width: 60px">
    <div style="padding: 0px 0 0 15.5px; width: 700px">

      <!-- 
	All .aspx pages using the control will have to set ActiveButton property for this control. The pages will
	also have to call setLabelText() function on its body load.
 -->
      <!-- Start changes for UW Version Rating -- 16/02/2009-->
      <!--<table width="80%" cellspacing="0" cellpadding="0">-->
      <table width="100%" cellspacing="0" cellpadding="0">
        <!-- End changes for UW Version Rating -- 16/02/2009-->
        <tbody>
          <tr>
            <!-- ie8-->
            <td height="5px"></td>
          </tr>
          <tr>
            <td height="5" width="100%">
              <table id="HeaderText1_TblBorder" cellspacing="0" cellpadding="0" border="1" class="subcontainer" width="773px">
                <tbody>
                  <tr>
                    <td>
                      <table cellpadding="0" border="0" width="773px">
                        <tbody>
                          <tr>
                            <td valign="center">
                              <span id="HeaderText1_lblInsured" class="StyledLabelHeader">Insured's Name: safsdfdsf</span>
                            </td>
                            <td align="right" valign="center">&nbsp;
                              <span id="HeaderText1_lblQuote" class="StyledLabelHeader">Quote Number: Q164692   </span>
                            </td>
                          </tr>
                        </tbody>
                      </table>
                    </td>
                  </tr>
                </tbody>
              </table>

            </td>
          </tr>
        </tbody>
      </table>

    </div>
  </form>
  <span id="Label13" class="StyledLabel" style="width:120px;z-index: 131; position: absolute; top: 134px; left: 16px">Retroactive Date:</span>
  <input name="hdnIsUnderwriter" type="hidden" id="hdnIsUnderwriter" value="1">
  <!-- 2.8 Release -->
  <input name="hdn_appstate" type="hidden" id="hdn_appstate" value="1">
  <input name="hdn_state_effectivedate" type="hidden" id="hdn_state_effectivedate" value="4/6/2012">
  <input name="hdnRetro" type="hidden" id="hdnRetro" value="12/3/2018">
  <input name="hdnState" type="hidden" id="hdnState" value="CA">
  <input name="hdn_statename" type="hidden" id="hdn_statename" value="CA">
  <input name="hdninstalldate" type="hidden" id="hdninstalldate">

  <!-- 2.8 Release -->

  <!--CHANGE START: RELEASE 3.7.1 TURNING ON FL; QCID:9000 DONE BY: N9V333-->
  <input name="hdnRenVer" type="hidden" id="hdnRenVer" value="1">
  <!--CHANGE END: RELEASE 3.7.1 TURNING ON FL; QCID:9000 DONE BY: N9V333-->


</body>

</html>

Проблема 1: Иногда открывается новое окно, но с ошибкой.Прикрепленный снимок экрана для лучшей идеи.

Проблема 2: Некоторое время после переключения обратно в родительское окно согласно моему коду, он не может найти элемент в родительском окне. введите описание изображения здесь

Код, используемый для переключения в новое окно и обработки элемента в окне:

String winHandleBefore = driver.getWindowHandle();
driver.findElement(By.id("btnAddRemoveAST")).click();
for(String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
driver.findElement(By.xpath("//input[@name='txtASTID']")).sendKeys("Test");
driver.close();
driver.switchTo().window(winHandleBefore);
driver.findElement(By.xpath("//input[@name='btnNext']")).click();

1 Ответ

0 голосов
/ 04 декабря 2018

Передайте заголовок окна для функции ниже, если выход из окна не имеет ничего общего с драйвером.Вы должны пометить этот шаг как неудачный.

public static void SwitchToPopup (this IWebDriver driver, string windowTitle )
        {
                           driver.Wait(2);
                driver.Sync();
                string current = driver.CurrentWindowHandle;
                foreach (string handle in driver.WindowHandles)
                {
                    driver.SwitchTo().Window(handle);
                    if (driver.Title.Contains(windowTitle))
                    {
                        Reporter.Logtofile("Error window displayed: " + WindowTitle,Status.Info);
                        break;
                    }
                }
            }
...