selenium - ExpectedConditions.presenceOfAllElementsLocatedBy 有多少?
问题描述
ExpectedConditions.presenceOfAllElementsLocatedBy(locator)
webDriver如何知道定位器定位了多少元素?
解决方案
如果您查看代码,它只会抓取与提供的定位器匹配的所有元素。它唯一捕捉到的是StaleElementReferenceException
. 完整的代码在下面,带有指向源的链接。
/// <summary>
/// An expectation for checking that all elements present on the web page that
/// match the locator.
/// </summary>
/// <param name="locator">The locator used to find the element.</param>
/// <returns>The list of <see cref="IWebElement"/> once it is located.</returns>
public static Func<IWebDriver, ReadOnlyCollection<IWebElement>> PresenceOfAllElementsLocatedBy(By locator)
{
return (driver) =>
{
try
{
var elements = driver.FindElements(locator);
return elements.Any() ? elements : null;
}
catch (StaleElementReferenceException)
{
return null;
}
};
}
推荐阅读
- angular - 传递正确的上下文以在 Angular 的对话框数据中运行
- r - With two groups in dplyr output I want second group to be in descending order
- android-studio - Kotlin Scratch File Android Studio readline()
- javascript - npx 创建反应应用程序
在某个部分后停止运行 - mysql - Strange problem with double in database mysql
- angular - Angular 8 cannot match nested route
- text-editor - 创建文本程序
- javascript - 查找元素的 XPath
- html - 如何对齐这些项目?
- python - 有没有办法在数组列表中找到唯一二进制数组的计数?