首页 > 解决方案 > 如何使用 Selenium C# 创建包含 display:Block display: none 的加载微调器方法?

问题描述

我无法在我的测试中抓住装载机。我需要创建一个方法来帮助我查看加载程序何时不再可见。由于这个问题,我无法选择任何页面元素。

代码尝试:

public static void SeeNoLoaderInQD() 
{ 
    Actor.Wait.UntilElementIsNotDisplayed(Elements.QDLoader); 
    Assert.IsTrue(Elements.SeeException.Count == 0); 
} 

快闪

标签: c#seleniumkendo-ui

解决方案


我会尝试这样的事情:

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;意味着加载器不再可见。


推荐阅读