gpt4 book ai didi

c# - 将 wait.until 与 selenium 一起使用时如何记录超时时间?

转载 作者:行者123 更新时间:2023-11-30 17:25:43 25 4
gpt4 key购买 nike

目前我正在使用以下wait.until代码:

wait.until(ExpectedConditions.elementToBeClickable(By.id<locator>));

我希望能够识别此代码耗时最长的场景。我在多个地方使用此代码,但有没有一种方法可以通过 selenium 记录超时,而无需在调用此代码之前/之后添加秒表?

最佳答案

我想到的最佳方法是扩展方法:

    public static IWebElement LoggedUntil(this WebDriverWait wait, Func<IWebDriver, IWebElement> condition)
{
var watch = System.Diagnostics.Stopwatch.StartNew();

try
{
return wait.Until(condition);
}
finally
{
watch.Stop();
var elapsedSeconds = watch.Elapsed.TotalSeconds;
Console.WriteLine($"Wait took: {elapsedSeconds} Seconds");
}
}

在此之后,我可以将所有使用 .Until 的引用更改为使用 .LoggedUntil

   protected IWebElement FindElement(By by)
{
Console.WriteLine($"Find {by}");
return Wait.LoggedUntil(ExpectedConditions.ElementExists(by));
}

关于c# - 将 wait.until 与 selenium 一起使用时如何记录超时时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57868649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com