【发布时间】:2021-12-08 00:50:04
【问题描述】:
我应该将元素添加到 elementCache,其中 string => 定位器(例如元素的 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
}```
【问题讨论】:
-
什么是字典键?大概您将项目放入字典中,以便您可以通过键查找它们,对吧?
-
字典键是xpath,是的,你是对的
标签: c# .net selenium-webdriver automation