Selenium WebDriver throws Timeout exceptions sporadically

前端 未结 8 1341
感情败类
感情败类 2020-12-01 07:43

Using selenium for ui tests on our project. We are running the newest version 2.30.0. We use Firefox WebDriver and are running Firefox 19.0.

Generally said the ui te

相关标签:
8条回答
  • 2020-12-01 08:17
    public static IWebElement WaitForElementVisible(By selector, uint timeout = Config.DefaultTimeoutSec)
        {
            IWebDriver driver = Browser.Instance.Driver;
    
            if (timeout > 0)
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
    
                wait.Until(ExpectedConditions.ElementIsVisible(selector));
                return driver.FindElement(selector);
            }
            else
            {
                // Search for element without timeout 
                return driver.FindElement(selector);
            }
        }
    

    We use this to prevent such Element not found failures and it works like a charm.

    There is also a different Version if the Element can be there, but doesn't have to be visible.

    Just use ExpectedConditions.ElementExists(selector) instead of ExpectedContitions.ElementIsVisible(selector)

    edit: Browser.Instance.Driver is a class containing the instanced driver

    0 讨论(0)
  • 2020-12-01 08:21

    Try this code:

      DesiredCapabilities caps = DesiredCapabilities.Firefox();   
    
     //set the timeout to 120 seconds
     IWebDriver driver = new RemoteWebDriver(new Uri("<app_url>"), caps, TimeSpan.FromSeconds(120));
    
    0 讨论(0)
提交回复
热议问题