c# - 如何使用 Selenium C# 创建包含 display:Block display: none 的加载微调器方法?
问题描述
我无法在我的测试中抓住装载机。我需要创建一个方法来帮助我查看加载程序何时不再可见。由于这个问题,我无法选择任何页面元素。
代码尝试:
public static void SeeNoLoaderInQD()
{
Actor.Wait.UntilElementIsNotDisplayed(Elements.QDLoader);
Assert.IsTrue(Elements.SeeException.Count == 0);
}
解决方案
我会尝试这样的事情:
public static void WaitForElementAttributeValue(this IWebDriver driver, By by, string attribute, string value)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(d => d.FindElement(by).GetAttribute(attribute).Contains(value));
}
您可以为您的场景调用此方法,如下所示:
driver.WaitForElementAttributeValue(By.Id("line-scale-loader"), "style", "display: none;");
调用此方法时,您是在告诉 WebDriver 等到 WebElement 的style
属性值等于display: none;
意味着加载器不再可见。
推荐阅读
- node.js - 无法在 Apple M1 air 上构建节点 rdkafka
- python - 如何在 Python Kivy 中设置 UI 主题图像?
- java - 时间总和不等于模拟的持续时间
- c# - Blazor WASM Net 6 Preview 4 Azure AD - 尝试登录时出错:'无法读取未定义的属性'toLowerCase'
- nginx - 没有从入口控制器获取源 IP
- python - 尝试使用 while 循环从扩展列表派生汇总列表会导致无限循环
- spring-boot - 如何启动和停止春季预定工作?
- javascript - 无法从函数中获取值
- c# - 如何在 C# 中使用二维数组绘制灰度图像?
- python - 无法解析完整的网页,使用 BeautifulSoup