繁体   English   中英

如何从字典中获取 IWebElement<string, IWebElement>

[英]How can I get IWebElement from dictionary<string, IWebElement>

我应该将元素添加到 elementCache,其中 string => locator(例如 xpath 或元素的 id),并且当我重复某些操作方法时 FindElement 将使用字典中的 IWebElement


Dictionary<string, IWebElemebnt> elementCache = new();

public bool IsEnableElement(UiElement locator)
{
   if(locator.IsVisible())
   {
      return true;
   }
   return false;
}

public IWebElement FindElement(UiElement locator)
{
   if(IsEnableElement(locator)
   {
      //return IWebElement;
   }
   else
   {
      var webElement = FindElementInParent(FindParent(locator), locator.By);

      elementCache.Add(locator.ToString(), webElement);

      return webElement;  
   }
   // check dictionary if the element exists in the dictionary, then return 
   //IWebElement, otherwise find and add to the dictionary and return it
}```

您需要使用定位器作为键。 然后你可以用它在字典中查找。 像这样:

public IWebElement IsEnableElement(string locator)
{
     if (elementCache.ContainsKey(locator ?? "") && elementCache[key].Key == locator) 
        {
           return elementCache[locator].Value;
        }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM