3

I have a method which waits explicitly until the element exists. It was working fine until I upgraded my driver to 2.37. The problem is even though I pass timeout parameter in my method, it doesn't seem to wait that long, instead it throws the "elementNotFound" exception. I believe it is still using the default webdriver's timeout. Below is the code I am using in my method ( this is not my original code, I grabbed it from stackoverflow). I even tried TimeSpanFromMInutes and it doesn't seem to wait that long. Has something got broken in 2.37?

public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds)
    {
        if (timeoutInSeconds > 0)
        {
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            return wait.Until(drv => drv.FindElement(by));
        }
        return driver.FindElement(by);
    }`
4

1 に答える 1

0

機能しなくなった理由はわかりませんが、ExpectedConditions を使用して要素が存在するかどうかを確認できます。私はそれをテストし、2.37で動作しているようです:

if (timeoutInSeconds > 0)
{
    var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
    wait.IgnoreExceptionTypes(typeof(OpenQA.Selenium.NoSuchElementException)); 
    return wait.Until(ExpectedConditions.ElementExists(by));
}
return driver.FindElement(by);
于 2013-11-05T03:11:09.423 に答える