0
我在C#中使用Selenium Webdriver 2.30。我很感激,如果有人能告诉我如何在以下结构中点击链接(id =“e”)。使用Selenium Webdriver在dl,dt中查找元素C#
<frame name = "a">
#document
<html>
<head></head>
<body>
<div id = "b">
<dl id= "c">
<dt class = "d">
<a href = "http://somewhere.com" id = "e" class> Go to somewhere</a>
</dt>
<dt>
<a href = "http://something.com" id = "f"> Find something </a>
</dt>
</dl>
</div>
</body>
</html>
</frame>
我试图
selenium.SwitchTo().Frame("a");
selenium.FindElement(By.XPath("//a[@id=\"e\"]")).Click();
并试图
selenium.SwitchTo().Frame("a");
selenium.FindElement(By.XPath("//div[@id='b']/dl[1]/dt[1]/a")).Click();
我也试过
selenium.SwitchTo().Frame("a");
selenium.FindElement(By.LinkText("Go to somewhere")).Click();
不幸的是,他们没有工作。问题可能是因为定义列表中的元素有些不同,但我还没有弄清楚。
感谢哥们。我的团队领导帮助解决了这个问题。因为在此之前我有另一个Swithto框架。所以它实际上在切换帧(“a”)时失败了。该解决方案非常简单,只需添加selenium.Navigate()。Refresh();切换到帧之前。根据我的理解,在切换到帧之后,除非您进行页面刷新,否则webdriver将忽略其他帧。 – 2013-04-12 17:32:43
不,'selenium.Navigate()。Refresh();'可以工作,但这不是处理这个问题的理想方法。如果你想跳出框架,你应该使用'selenium.SwitchTo()。DefaultContent()'[参见ITargetLocator.cs#67](https://code.google.com/p/selenium/source/browse/dotnet /src/WebDriver/ITargetLocator.cs#67)。这将让webdriver切换回来,然后使用另一个'selenium.SwitchTo()。Frame();'。顺便说一下,如果您发现它有帮助并解决了您的问题,请随时选择我的答案作为已接受的答案。 – 2013-04-12 20:56:15