Selenium C# WebDriver: Wait until element is present

前端 未结 24 3050
礼貌的吻别
礼貌的吻别 2020-11-22 08:53

I want to make sure that an element is present before the webdriver starts doing stuff.

I\'m trying to get something like this to work:

WebDriverWait w         


        
24条回答
  •  自闭症患者
    2020-11-22 09:52

    We can achieve that like this:

    public static IWebElement WaitForObject(IWebDriver DriverObj, By by, int TimeOut = 30)
    {
        try
        {
            WebDriverWait Wait1 = new WebDriverWait(DriverObj, TimeSpan.FromSeconds(TimeOut));
            var WaitS = Wait1.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.PresenceOfAllElementsLocatedBy(by));
            return WaitS[0];
        }
        catch (NoSuchElementException)
        {
            Reports.TestStep("Wait for Element(s) with xPath was failed in current context page.");
            throw;
        }
    }
    

提交回复
热议问题