【发布时间】:2015-03-21 16:26:21
【问题描述】:
<iframe id="ifrm1">
<head>
<html>
<body>
<iframe id="ifrm2">
<head>
<html>
<body>
<a id="whatever" href="http://site1.com"></a>
</body>
</html>
</head>
</iframe>
</body>
</html>
</head>
</iframe>
c#
FirefoxProfile prof = new FirefoxProfile("D:\\Documents and Settings\\username\\Application Data\\Mozilla\\Firefox\\Profiles\\myporfile");
dynamic ff = new FirefoxDriver(new FirefoxBinary("D:\\Program Files\\Mozilla Firefox\\Firefox.exe"), prof, TimeSpan.FromMinutes(10));
ff.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(10));
try {
ff.Navigate().GoToUrl("http://exemple.com");
88:
try {
45:
ff.SwitchTo().Frame("ifrm1");
ff.SwitchTo().Frame("ifrm2");
} catch (NoSuchFrameException exx) {
goto 45;
}
try {
66:
IWebElement oo = ff.FindElement(By.TagName("a"));
oo.Click();
ff.Close();
} catch (NoSuchElementException ex) {
goto 66;
}
} catch (WebDriverTimeoutException ex) {
goto 88;
}
vb.net
Dim prof As FirefoxProfile = New FirefoxProfile("D:\Documents and Settings\username\Application Data\Mozilla\Firefox\Profiles\myporfile")
Dim ff = New FirefoxDriver(New FirefoxBinary("D:\Program Files\Mozilla Firefox\Firefox.exe"), prof, TimeSpan.FromMinutes(10))
ff.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(10))
Try
ff.Navigate().GoToUrl("http://exemple.com")
88: Try
45: ff.SwitchTo().Frame("ifrm1")
ff.SwitchTo().Frame("ifrm2")
Catch exx As NoSuchFrameException
GoTo 45
End Try
Try
66: Dim oo As IWebElement = ff.FindElement(By.TagName("a"))
oo.Click()
ff.Close()
Catch ex As NoSuchElementException
GoTo 66
End Try
Catch ex As WebDriverTimeoutException
GoTo 88
End Try
所以我处理超时异常并处理 NoSuchElementException 以检查元素是否可用,但有时会触发,有时不会,
有没有更好的方法:
1- 不等待记录。准备好
2- 监视直到第二个 iframe 内的锚点出现并触发它
感谢您的帮助!
【问题讨论】:
-
@Saifur 你是什么意思? .net 以及
-
您使用的是哪种语言绑定?另外,如果我正确地看到它,唯一的问题是在第二个
iframe内找到a标签?对吗? -
@Saifur 不仅找到它,等待它,一旦它出现然后触发它,我正在使用 vb.net/c# 任何东西..
标签: c# .net iframe selenium-webdriver