我看过很多关于在 Selenium 中处理帧之间切换的帖子,但它们似乎都为以下方法引用了 Java“ExpectedConditions”库。
ExpectedConditions.frameToBeAvailableAndSwitchToIt
我想知道是否有任何 C# 实现在任何地方或者是否有人有任何这样的解决方法?
干杯
请您参考如下方法:
在 C# 绑定(bind)中没有直接的等价物,但您自己可以很容易地做到这一点。
请记住,Selenium 是开源的,所以让我们挖掘源代码。 Here is the Java ExpectedConditions和 here is the C# set .
那么Java版是做什么的呢?好吧,我告诉你的不多。
try {
return driver.switchTo().frame(frameLocator);
} catch (NoSuchFrameException e) {
return null;
}
它所做的只是尝试切换到您告诉它的框架,并提供它成功(因为在尝试这样做时没有异常(exception)),然后假设它可以继续。
所以,您需要做的就是在 C# 中做同样的事情,比如(未编译):
public static Func<IWebDriver, bool> WaitUntilFrameLoadedAndSwitchToIt(By byToFindFrame)
{
return (driver) =>
{
try
{
return driver.SwitchTo().Frame(driver.FindElement(byToFindFrame));
}
catch (Exception)
{
return null;
}
return true;
};
}
保持相同的概念:尝试找到框架并切换到它,任何异常然后我们返回 null 并强制调用者(通常是 WebDriverWait 实例) 再次迭代。返回 true 将告诉调用者我们很高兴我们可以继续前进。
所有等待和预期条件类都位于 OpenQA.Selenium.Support.UI 命名空间中,该命名空间位于 WebDriver.Support.dll 程序集中。
