Selenium waiting until element equals something

c#, selenium, selenium-webdriver

Solution

Couple of things here. The implementation of `Until()` is wrong here. You either have to use `ExpectedConditions` here or write a custom functions(see bellow).See the api

By byXpath = By.XPath("//*[@id='watch-toolbar']/aside/div/span");
IWebElement element =
    new WebDriverWait(_driver, TimeSpan.FromSeconds(90)).Until(ExpectedConditions.ElementExists(byXpath));


if (element.Text.Trim() == "3")
{
    //Pass this
}

Another options with LINQ

string watchprogress = new WebDriverWait(_driver, new TimeSpan(10)).Until(e => e.FindElement(byXpath)).Text.Trim();

if (watchprogress == "3")
{

}

Or

Simply if you want to wait until the `element` get's the text `3` use a `bool` indicator

bool watchprogress  =
                new WebDriverWait(_driver, new TimeSpan(10)).Until(e => e.FindElement(byXpath)).Text.Trim().Equals("3");

Or

 IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
 wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
 //First wait for the page to be completely loaded.
 WebDriverWait wait2 = new WebDriverWait(driver, TimeSpan.FromSeconds(90));
 wait2.IgnoreExceptionTypes(typeof(StaleElementReferenceException));
 wait2.Until(d => d.FindElement(By.XPath("//*[@id='watch-toolbar']/aside/div/span")).Text.Contains("3"));

Problem

C#, Winform, Selenium Firefox webdrivers. Basically I need to wait till a certain element equals something in my program this is what i tried ``` public static string Watchprogress; Watchprogress = driver.FindElement(By.XPath("//*[@id='watch-toolbar']/aside/div/span")).Text.ToString(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(90)).Until(Watchprogress == "3"); //And this WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(90)).Until(By.XPath("//*[@id='watch-toolbar']/aside/div/span")).Text.ToString() == "3"); ``` got this error The type arguments for method 'OpenQA.Selenium.Support.UI.DefaultWait.Until(System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly. 5079 Still kinda new to selenium so i've been just doing trial and error.

Original source