selenium 中PageFactory [CacheLookup]属性
selenium 中有个现成的框架 就是pagefactory 。我们可以实现页面元素和行为的分离。
在定义元素中如下啊
[FindsBy(How = How.XPath, Using = "//table[@class='Tab01']/tbody/tr/td[3]")]
[CacheLookup]
private IList<IWebElement> prodNamePrice;
我们可以看到 是用。xpath 的查找方式
但是第二个【cachelookup】 是个什么东西了 来看原文啊
CacheLookup
One last thing that remains with PageFactory is the CacheLookupAttribute. This is important because it can be used to instruct the InitElements method to cache the element once its located. In other words, any attribute marked[CacheLookup] will not be searched over and over again – this is especially useful for elements that are always going to be there (not always true for AJAX apps). So, we can search once and cache. All elements used in this article can be defined by this declarative tag as they are static and are always present.
简单说来 就是元素的缓冲 在用 PageFactory.InitElements(MyWebDriver.driver,pageclass); 时会用到 (我想的啊 )。你要确保这些有这些属性的页面元素是保持不变的 。原因就是上面说的饿,可能在ajax中 这个元素是变化的 ,可是用的时候用的是缓存 ,没有拿到最新的元素,所以 不能使用在ajax元素中
这是今天的收获吧 。下班了 。锻炼身体去先。

浙公网安备 33010602011771号