title: How to make program (c#, selenium) wait to periodically check if the 'if' condition is met
body: <p>I intend to increment the counter by 1 when the url changes and return the final count, eg 10 if url changes 10 times. The program has to wait until the user clicks a button or something on the webpage which leads to the change of url. The code isn't giving the desired output, infact the counter isn't incrementing at all.</p>
  <pre><code>    public partial class Counter : Form 
      {    
          int count = 0;
          string url = &quot;...&quot;;
          private IWebDriver driver = new ChromeDriver();
          
          public Counter()
          {
          
             InitializeComponen();
             driver.Navigate().GoToUrl(url);
          }
          
          private void textBox.TextChanged(object sender, EventArgs e)
          {
              textBox.Text = &quot;Click: &quot; + count.ToString();
              driver.Manage().Timeout().ImplicitWait = TimeSpan.FromSeconds(10);
              if (driver.Url != url)
              {
                   count++;
                   textBox.Text = &quot;Click: &quot; + count.ToString();
          
              }
          }
          
              private void resetButton_Click(object sender, EventArgs e)
              {
                  count = 0;
                  textBox.Text = &quot;Click: &quot; + count.ToString();
          
              }
          }
     }
  </code></pre>