【发布时间】:2015-09-10 20:21:33
【问题描述】:
我尝试使用 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>
但是什么也没发生,我似乎无法选择要点击的链接。你看到我的代码有什么错误吗?
【问题讨论】:
-
你的 html 不应该说 class="pop" (使用引号)吗?你是复制粘贴还是自己写的?
-
嗨,它是一对复制和粘贴的组合。我在代码中的其他地方使用 ' 并且它可以工作
-
我的建议:最好尽可能准确,否则对您的帮助是非常不同的,因为有很多方法会犯错误,我们需要首先排除尽可能多的可能性
-
好的,这是个好建议!我使用此处找到的代码:stackoverflow.com/questions/27608921/…(最佳答案的“替代方式”)。