我一直在搜索所有可以找到的相关主题,但尚未找到有效的答案。我有一个网站可以生成要与之交互的PDF文档(以及该文档的下载链接),并且Selenium一直牢记其无法通过ID,CSS或xPath定位器找到该元素。
代码如下:
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl(url);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(
ExpectedConditions.ElementToBeClickable(By.Id("lnkMeetingAgenda_9829")));
Assert.That(element.Displayed);
element.Click();
driver.Close();
我不认为该元素位于不同的框架中,因为当我查看网站时看不到它。任何帮助将不胜感激!
编辑:我相信现在更多地了解HTML了,我知道了答案。该ID并不是唯一的,因为它有2个实例,但这并不能解释为什么xPath或CSS无法正常工作。感谢您提供任何其他帮助。
<a href="/OnBaseAgendaOnline/Meetings/ViewMeeting?id=9829&doctype=1"
title="View Agenda for Audio/Video Media Meeting with Captions Hyland County Council on 5/22/2018 4:55:42 PM" id="lnkMeetingAgenda_9829">Agenda</a>
<a href="/OnBaseAgendaOnline/Documents/Downloadfile/Audio_Video_Media_Meeting_with_Captions_9829_Agenda_5_22_2018_4_55_42_PM.pdf?documentType=1&meetingId=9829" id="lnkMeetingAgendaDoc_9829" target="_blank"
title="Download Agenda for Audio/Video Media Meeting with Captions Hyland County Council on 5/22/2018 4:55:42 PM">
<img src="/OnBaseAgendaOnline/Images/PDF_16x16.png" />
</a>
<span> </span>
<a href="/OnBaseAgendaOnline/Meetings/ViewMeeting?id=9829&doctype=1"
id="lnkViewMedia_9829" title="View Media for Audio/Video Media Meeting with Captions Hyland County Council on 5/22/2018 4:55:42 PM">View Media</a>
<span> </span>
</td>
<td class="hidden-xs visible-sm visible-md visible-lg">
<span> </span>
<a href="/OnBaseAgendaOnline/Meetings/ViewMeeting?id=9829&doctype=1"
title="View Agenda for Audio/Video Media Meeting with Captions Hyland County Council on 5/22/2018 4:55:42 PM" id="lnkMeetingAgenda_9829">Agenda</a>
<a href="/OnBaseAgendaOnline/Documents/Downloadfile/Audio_Video_Media_Meeting_with_Captions_9829_Agenda_5_22_2018_4_55_42_PM.pdf?documentType=1&meetingId=9829" id="lnkMeetingAgendaDoc_9829" target="_blank"
title="Download Agenda for Audio/Video Media Meeting with Captions Hyland County Council on 5/22/2018 4:55:42 PM">
<img src="/OnBaseAgendaOnline/Images/PDF_16x16.png" />
答案 0 :(得分:0)
碰巧我要查找的ID嵌套在“隐藏”元素下,因此我使用IJavaScriptExecutor“单击”了该元素。下面是我用来执行此操作的代码。
DataSet
感谢大家提供帮助!