簡體   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