C# 如何使用路由获取页面上的所有iFrame?
因此,我正在创建一个C# 如何使用路由获取页面上的所有iFrame?,c#,selenium,iframe,infinite-loop,C#,Selenium,Iframe,Infinite Loop,因此,我正在创建一个BaseIFrame类,以便在不使用id、xpath或任何特定于DOM的东西的情况下,从任何页面通用地解析嵌套的iframe。我目前正在“路由”我的iFrame,方法是获取名称,将它们存储在字符串中,然后切片特定的iFrame名称并切换到它。我的目标是解析切片名称中的所有嵌套帧 但是,当我运行它时,我会得到a.)无限循环或b.)元素,并将哈希代码作为ID附加到字典中 我怎样才能解决这个问题 BaseiFrameClass: namespace [Confidental nam
BaseIFrame
类,以便在不使用id、xpath或任何特定于DOM的东西的情况下,从任何页面通用地解析嵌套的iframe。我目前正在“路由”我的iFrame,方法是获取名称,将它们存储在字符串中,然后切片特定的iFrame名称并切换到它。我的目标是解析切片名称中的所有嵌套帧
但是,当我运行它时,我会得到a.)无限循环或b.)元素,并将哈希代码作为ID附加到字典中
我怎样才能解决这个问题
BaseiFrame
Class:
namespace [Confidental namespace] {
public class BaseIFrame {
protected IWebDriver _driver;
private ReadOnlyCollection<IWebElement> _iframes;
public BaseIFrame(IWebDriver _driver) {
this._driver = _driver;
_iframes = _driver.FindElements(By.TagName("frame"));
_iframesSize = _iframes.Count();
}
public ReadOnlyCollection<IWebElement> getFrames() {
return _iframes;
}
public void GetAlliFrames<T>(IWebDriver driver)
{
string frameRoute = "main:topMenu";
Dictionary<string, IWebElement> returnValue = new Dictionary<string, IWebElement>();
int startPosition = frameRoute.IndexOf("");
string firstOuterFrameRoute = frameRoute.Substring(startPosition,
frameRoute.IndexOf(":", startPosition) - startPosition);
var firstOuterFrame = driver.FindElement(By.Name(firstOuterFrameRoute));
driver.SwitchTo().Frame(firstOuterFrame);
try
{
for (var i = 0; _iframesSize > i; i++)
{
returnValue.Add(_iframes[i].ToString(), _iframes[i]);
}
}
catch (Exception e)
{
Debug.WriteLine(e.FormatExceptionMessage(this));
throw;
}
}
}
}
[TestMethod]
public void AssertiFrameLength()
{
Login();
var expected = 0;
BaseIFrame bif = new BaseIFrame(_driver);
bif.GetAlliFrames<IWebElement>(_driver);
var elementSize = _driver.FindElements(By.TagName("*")).Count;
for (var i = 0; i < elementSize; i++)
{
var iframesSize = _driver.FindElements(By.TagName("frame")).Count;
expected += iframesSize;
}
var actual = bif.getFrames();
Assert.AreEqual(expected, actual.Count);
}