7

最新の Chrome と Webdriver 2.33 を使用していますが、IgnoreExceptionTypes. 以下のコードでは、webdriver も期待どおりに待機しますが、実際には例外を無視しません。

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(8));
wait.IgnoreExceptionTypes(
    typeof(WebDriverTimeoutException),
    typeof(NoSuchElementException)
);  
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(firstResultX)));

コードは try/catch にあります。try/catch の外に移動しようとしましたが、同じ問題が発生しました。ここからどこに行けばよいかわかりません。助けていただければ幸いです。

4

2 に答える 2

1

FluentWaits を使用できます。

Wait<WebDriver> wait = new FluentWait<WebDriver>(getDriverInstance())
                .withTimeout(timeoutSeconds, TimeUnit.SECONDS)
                .pollingEvery(sleepMilliSeconds, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

wait.until(<Your expected condition clause.>);

これで問題が解決しない場合はお知らせください。

于 2014-08-30T06:30:12.790 に答える
0

C# の場合、異なる待機は -

      ` //Implicit Wait - Once set it remains till the life of the session
        Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

        //Explicit Wait - Polling interval is 250ms
        //using OpenQA.Selenium.Support.UI; 
        WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
        //this wait utility ignores no such element errors by default
        IWebElement webElement = wait.Until(e => e.FindElement(By.Id("value")));

        //Fluent wait - Polling interval is set by us
        WebDriverWait fluentWait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30))
        {
            PollingInterval = TimeSpan.FromSeconds(2)
        };
        fluentWait.IgnoreExceptionTypes(typeof(AccessViolationException), typeof(NoSuchElementException));
        IWebElement element = wait.Until(e => e.FindElement(By.Id("value")));`
于 2021-03-30T10:35:24.507 に答える