24 Temmuz 2017 Pazartesi

thread. sleep selenium alternative

Thread.Sleep() is a very discouraged way to implement your waits
This code is outlined on the selenium documentation http://seleniumhq.org/docs/04_webdriver_advanced.html
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement category = wait.Until<IWebElement>((d) =>
    {
        return d.FindElement(By.Id("ctl00_ContentPlaceHolder1_Filter"));
    });
That is an example of an explicit wait where selenium will not execute any actions until your element is found
An example of an implicit wait is:
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
IWebElement category = driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_Filter"));
In implicit waits the driver will wait for a given amount of time and poll the DOM for any elements that do not exist.
EDIT
public WaitForElement(string el_id)
{
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    IWebElement category = wait.Until<IWebElement>((d) =>
    {
        return d.FindElement(By.Id(el_id));
    });
}