用selenium处理一个弹出窗口
本文关键字:一个 窗口 selenium 处理 | 更新日期: 2023-09-27 18:12:10
我尝试使用selenium在网页上自动下载。当我点击一个按钮时,会出现一个空白的弹出框。大约60秒后,一个链接出现在弹出窗口上。我想点击那个链接。下面是我一直在使用的代码:
//the button that makes the popup appear
element = driver.SwitchTo().Frame(detailFrame).FindElement(By.XPath("//div[@class='smenu']/input[@value='Imprimer']"));
//I save the current handle so that I can get back to it later
currentHandle = driver.CurrentWindowHandle;
//the finder is supposed to return the handle of the popup
PopupWindowFinder finder = new PopupWindowFinder(driver);
string popupWindowHandle = finder.Click(element);
driver.SwitchTo().Window(popupWindowHandle);
//I wait for the link to appear on the popup
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(100));
driver.FindElement(By.XPath("//body[@class='pop']/descendant::a[@href='/ppm/display_pdf.do']")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));
下面是弹出窗口的html代码:
<body class=pop onunload=closePopup();>
<table class=table height="90%" align=center>
<tbody>
<tr class=center height="30%">
<td rowSpan=”1” colSpan=”1”>
<a href="/ppm/display_pdf.do">Eng_X82.pdf </a>
</td>
</tr>
</body>
</table>
但是什么都没有发生,我似乎无法选择链接来点击它。
你可以这样写。
Alert aBox =driver.switchTo().alert();
aBox.accept();
点击弹出窗口的OK
Alert aBox =driver.switchTo().alert();
aBox.dismiss();
点击取消弹出