c# - 当给定类的元素不存在于小型 DOM 中时,检查它们的不可见性需要很长时间
问题描述
在我点击任何链接之前,我确保页面中的任何地方都没有可见的加载器微调器。出于某种原因,在根本没有微调器的页面上最多需要 40 秒,而在所有其他页面上,它的闪烁速度很快。
为了确保没有微调器,我编写了这个方法:
public static void WaitForSpinnersToDisappear(this IWebDriver driver)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
wait.Until(InvisibilityOfAllElementsLocatedBy(
By.ClassName("spinnertype1"),
By.ClassName("spinnertype2"),
By.ClassName("spinnertype3")));
}
它利用了这个功能:
public static Func<IWebDriver, bool> InvisibilityOfAllElementsLocatedBy(params By[] locators)
{
return driver =>
{
return locators.All(locator =>
{
var elements = driver.FindElements(locator); //this is incredibly slow
if (elements.Count == 0)
{
return true;
}
return driver.FindElements(locator).All(element => !element.Displayed);
});
};
}
由于某种原因 var elements = driver.FindElements(locator);
,在函数中调用的InvisibilityOfAllElementsLocatedBy
速度非常慢,仅对于具有短 DOM 且根本没有微调器的服务器生成页面。
解决方案
推荐阅读
- java - 带有 OOP 的 Java 应用程序杂货订购逻辑
- javascript - Javascript:单击元素而不是按钮
- java - 在 Spring Boot 上读取超时
- c# - ormlite async 方法使用 miniprofiler 抛出强制转换异常
- java - 如何跟踪曲目的结尾(MediaPlayer)
- c# - 如何在 Azure Signal R 中向经过身份验证的用户发送通知?
- javascript - 如何从用户 twitter api + javascript 检索所有推文
- python - Discord Self-Bot:加入服务器/公会时直接向用户发送消息
- javascript - Emscripten:使用 pthread 时的自定义消息处理程序
- biztalk - Can BizTalk be used to fetch data from a dynamic URL?