如何使用路由获取页面上的所有iFrame?

问题描述

因此,我正在创建一个await类,以从任何页面通用解析嵌套的iFrame,而无需利用ID,xpath或任何特定于DOM的类。我目前正在通过选择名称,将它们存储在字符串中,然后切片特定的iFrame名称并切换到它来“路由”我的iFrame。我的目标是解析切片名称中的所有嵌套框架。

但是,当我运行它时,我得到了a。)无限循环或b。)以哈希码作为ID附加到字典的元素。

我该如何解决

var licenses_grid = element( by.xpath(browser.params.constants.GENERALPATHS.LICENSES.LICENSESGRID)) .$$('.ui-grid-cell-contents.ng-binding.ng-scope')); 班级:

BaseIFrame

BaseiFrame类:

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;
            }
            
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)