我在Selenium中看到了许多关于处理帧间切换的文章,但它们似乎都引用了以下方法的Java‘ExpectedConditions’库。
ExpectedConditions.frameToBeAvailableAndSwitchToIt
我想知道是否在任何地方都有C#实现,或者是否有人做过这样的工作?
干杯
发布于 2018-11-08 09:05:21
这些答案都是老生常谈,我也有同样的问题。我能够使用nuget的SeleniumExtras.WaitHelpers.ExpectedConditions轻松实现这一目标。
//wait for 10 seconds max for the frame
WebDriverWaitwait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Id("FRAMEID")));
发布于 2015-07-17 05:16:27
我刚刚犯了这么一个丑恶的错误。为了未来在这里降落!
protected void SwitchToFrame(int iframe = 1)
{
var driver = GetWebDriver();
driver.SwitchTo().DefaultContent();
bool done = false, timeout = false;
int counter = 0;
do
{
counter++;
try
{
driver.SwitchTo().Frame(iframe);
done = true;
}
catch (OpenQA.Selenium.NoSuchFrameException)
{
if (counter <= Constants.GLOBAL_MAX_WAIT_SEC)
{
Wait(1);
continue;
}
else timeout = true;
}
} while (!done && !timeout);
if (timeout) throw new OpenQA.Selenium.NoSuchFrameException(iframe.ToString());
}
https://stackoverflow.com/questions/25201978
复制