title: OpenQA.Selenium.NoSuchElementException - C# Selenium
body: <p>A text has to be entered in a Textbox, a list auto-extends, and I need to select the first item. But it fails due to the exception; OpenQA.Selenium.NoSuchElementException. I tried using wait.Until(), but facing the same error.</p>
  
  <p><a href="https://i.stack.imgur.com/5YoO5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5YoO5.png" alt="Screenshot"></a></p>
  
  <pre><code>try
  {
       IWebElement cityList = driver.FindElement(By.XPath("value"));
       MouseClick(driver, cityList);
  }
  catch (OpenQA.Selenium.NoSuchElementException ex)
  {
       IWebElement cityList = driver.FindElement(By.XPath("value"));
       MouseClick(driver, cityList);
  }
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;input name="ctl00$cphmain$txtCity" type="text" maxlength="50" id="ctl00_cphmain_txtCity" class="mandsearchtxtbox" onkeypress="javascript:return ValidateInputAlphabeticValuesOnly(event);" onblur="javascript:return checkItemMsg(this)" style="width:180px;" autocomplete="off"&gt;
  &lt;div class="AutoExtenderHighlight"&gt;AMANDOLUWA&lt;/div&gt;
  </code></pre>
  
  <p>Code with wait.Until()</p>
  
  <pre><code>WebDriverWait wait1 = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
      wait.Until&lt;IWebElement&gt;((d) =&gt;
          {
              try
              {
                  return d.FindElement(By.XPath("//*[@id='citydiv']/div"));
                  MouseClick(driver, driver.FindElement(By.XPath("//*[@id='citydiv']/div")));
              }
              catch (OpenQA.Selenium.NoSuchElementException ex)
              {
                  return null;
                  MouseClick(driver, driver.FindElement(By.XPath("//*[@id='citydiv']/div")));
              }
          });
  </code></pre>
  
  <p><strong>Edit 2</strong></p>
  
  <p>HTML code for WebDriverException(Button)</p>
  
  <p><a href="https://i.stack.imgur.com/thTG3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/thTG3.png" alt="HTML code"></a></p>