如何使用切换到命令导航到弹出窗口

时间:2019-05-27 13:50:25

标签: forms switch-statement

我正在尝试使用“开关”移动到弹出窗口,但是我无法移动。

弹出窗口的代码为:

!DOCTYPE html><html>

<head><title>Memo Display/Update on Action (OFACREVIEW): OFACREVIEW</title>

<link rel='stylesheet' href='css/standard.css'>

<link rel='stylesheet' href='css/eWireCommon.css'>

<script>

</script>

</head>

<body onload='document.getElementsByName("reas_memo_out")[0].focus();document.getElementsByName("reas_memo_out")[0].select();'>

<FORM NAME='memoform'><H2 class='pageTitle inlineTitle' style='padding-left:54px;'>Memo</H2><center>

<table align='center' class='table1' style='border-style: solid; border-width: 1px; border-color: #bbbbbb; margin-bottom:5px; '>

<tr><td><textarea name='reas_memo_in' rows='7' cols='70' readonly='readonly'

style='background: #FFFFFF; color: #222222; overflow:auto; border-style: solid; border-width: 0px;border-bottom-width: 1px;'>TRANSACTION ORIGINALLY IN OFVPAYQ(17-OCT-2018 8:20:35/SYSTEM)</textarea>

</td></tr>

<tr style='background: #FFFFFF'><td>

<textarea name='reas_memo_fixed' rows='2' cols='70'

readonly='readonly'

style='color: red; overflow:auto; border-color: #bbbbbb; border-style: solid; border-width: 0px;border-bottom-width: 1px;'>Sent for OFAC Review</textarea>

</td></tr>

<tr style='background: #FFFFFF'><td>

<textarea name='reas_memo_out' rows='7' cols='70' tabindex='1'

style='color: #222222; overflow:auto; border-color: #bbbbbb; border-style: solid; border-width: 0px;'

onkeyup='javascript:textareaCounter (reas_memo_out, 920);'></textarea>

</td></tr>

</table>

<div>

<button TYPE='button' class='save_button button secondary2' Name='close_memo'

Value='' title='Save Memo/Close Window' onclick='javascript:goBackToWindowOpener("OFACREVIEW",1);'>

<span class='buttonLabel'>Save</span>

</button>

<button TYPE='button' class='clear_button button secondary2 onlyLabel' Value='' Name='clear_memo'

onclick='javascript:clearMemo();'>

<span class='buttonLabel'>Clear</span>

</button>

<button type='button' class='close_button button secondary2' name='close_memo'

Value='' title='Close Window' onclick='window.close()'></button>

</div>

</center></FORM></body></html>

我为切换窗口编写的硒C#代码为:

string OFACReviewpopup = AppBaseFL.isPopupPresent2();

if (OFACReviewpopup != null)

{

SetUpClass.myBrowser.switchToWindow(OFACReviewpopup);

myBrowser.Driver.FindElement(By.XPath("//form[@name='memo']"));

OFACObj.TxtOFACRevAreaMemo.SetValue("Sending the outgoing wire for OFAC Review");

AppBaseFL.WaitForTime(500);

myBrowser.Driver.FindElement(By.XPath("//input[@title='Save Memo/Close Window']")).Click();

AppBaseFL.WaitForTime(1000);

IAlert SentForOFACReview = AppBaseFL.isAlertPresent();

if (SentForOFACReview != null)

{

if (SentForOFACReview.Text.Contains("Send this payment for OFAC Review ?\r\nPress OK to Confirm."))

{

SentForOFACReview.Accept();

}

else

Assert.Ignore("Incorrect Alert, not able to release the payment to OFAC Review queue");

}

//SetUpClass.myBrowser.Driver.SwitchTo().Window(OFACReviewpopup).Close();

}

else

Assert.Ignore("Memo popup window not found, not able to release the payment to OFAC Review queue");

AppBaseFL.WaitForTime(1000);



public static string isPopupPresent2()

{

string popupWindowHandle = null;

try

{

WebDriverWait wait = new WebDriverWait(SetUpClass.myBrowser.Driver, TimeSpan.FromSeconds(10));

popupWindowHandle = wait.Until<string>((d) =>

{

string popupHandle = null;

if (SetUpClass.myBrowser.WindowHandles.Count > 0)

{

foreach (string handle in SetUpClass.myBrowser.WindowHandles)

{

if (handle != SetUpClass.GFTHomePageHandle)

{

popupHandle = handle;

break;

}

}

}

return popupHandle;

});

}

catch (NoSuchWindowException)

{

return null;

}

return popupWindowHandle;

}

但是我得到的结果是:

  

OpenQA.Selenium.WebDriverException:'对远程服务器的HTTP请求   用于URL的WebDriver服务器   http://localhost:54696/session/7318662c-f715-4bfd-8864-f56be901b521/window   60秒后超时。'

     

内部Web异常:

     

WebException:请求已中止:操作已超时。

0 个答案:

没有答案