【问题标题】:Selenium-Nunit How to wait for a several imagesSelenium-Nunit 如何等待几个图像
【发布时间】:2021-02-24 14:01:23
【问题描述】:

我想问你,如何等待多张图片显示(图片一张一张显示)。 in JAVA - Junit 是多重等待的代码

new WebDriverWait(driver, 10).until(ExpectedConditions.numberOfElementsToBe(By.(xpath("//div[@class = 'minions']//img"), number: 5));

我正在使用 Nunit (C#),但不知道如何执行类似于 junit 等待的操作。好像c#没有这样的东西。 有人可以帮帮我吗?

【问题讨论】:

  • 你可以使用while循环。 while( numofElements

标签: c# selenium selenium-webdriver junit nunit


【解决方案1】:

只需使用driver.FindElements(By.XPath("...")).Count 和显式等待:

var xpath = "//div[@class = 'minions']//img";
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

wait.Until(d => d.FindElements(By.XPath(xpath)).Count == 5);

如果你想要更容易重用的东西,你总是可以创建一个扩展方法:

public static class WebDriverWaitExtensions
{
    public static void UntilNumberOfElementsExist(this WebDriverWait wait, By locator, int number)
    {
        wait.Until(d => d.FindElements(locator).Count == number);
    }
}

并使用它:

var xpath = "//div[@class = 'minions']//img";
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

wait.UntilNumberOfElementsExist(By.XPath(xpath), 5);

【讨论】:

    猜你喜欢
    • 2014-03-05
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    相关资源
    最近更新 更多