title: "no such element" exception when using Selenium with C#
body: <p>I have a web page in my web project “CalculatorWeb” where I placed a single text box with id “txtNum1”</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="frmCalc"&gt;
          &lt;div style="padding-top:20px;"&gt;
              My Sample Text Box &lt;br/&gt;&lt;br/&gt;
              &lt;input id="txtNum1" type="text" /&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Nothing fancy so the page loads up as below</p>
  
  <p><img src="https://i.stack.imgur.com/lh5MZ.jpg" alt="Web Page Preview"></p>
  
  <p>Now I created a feature file “BrowserTest1.feature” to my project “Calculator.Specs”. The code as follows</p>
  
  <pre><code>Feature: BrowserTest1
  In order to check url
  As browser
  I want to be see url of page
  
  @mytag
  Scenario: Go to URL
      Given I have entered 'http://localhost:58529/'
      When I go to that url
      Then there is a text box on the page with id 'txtNum1'
  </code></pre>
  
  <p>I then code a file BrowserTest.cs for unit tests implementation</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using OpenQA.Selenium;
  using OpenQA.Selenium.Chrome;
  using OpenQA.Selenium.Support.UI;
  using TechTalk.SpecFlow;
  
  namespace Calculator.Specs
  {
      [Binding]
      class BrowserTest
      {
  
          public string urlPath;
  
  
          [Given(@"I have entered 'http://localhost:58529/'")]
          protected void SetURL()
          {
              string URLPath = "http://localhost:58529/";
              urlPath = URLPath;
          }
  
          [When(@"I go to that url")]
          protected void NavigateToURL()
          {
               using (var driver = new ChromeDriver())
               {
                   driver.Navigate().GoToUrl(urlPath);
               }
          }
  
  
          [Then(@"there is a text box on the page with id 'txtNum1'")]
          protected void TxtBoxExists()
          {
              bool txtExists = false;
              using (var driver = new ChromeDriver())
              {
                  IWebElement txtBox1 = driver.FindElement(By.Id("txtNum1"));
  
                  if (txtBox1 != null)
                  {
                      txtExists = true;
                  }
              }
              Assert.AreEqual(true, txtExists);
          }
      }
  }
  </code></pre>
  
  <p>As far as I am aware I do have all the required references for Visual Studio IDE to SpecFlow/Selenium integration</p>
  
  <p><img src="https://i.stack.imgur.com/wsBFh.jpg" alt="References Section"></p>
  
  <p>When I do run the unit test the web page loads up fine , however I get a failing test when I try to find the element with ID “txtNum1” even though the text box with that ID does exist on the page</p>
  
  <p><img src="https://i.stack.imgur.com/cIjsb.jpg" alt="Exception Message"></p>
  
  <p>Exception details appear as follows</p>
  
  <p><img src="https://i.stack.imgur.com/OcQNg.jpg" alt="Exception Details"></p>
  
  <p>Can anybody point me in the right direction as to what am I missing to enable Selenium to find the text box on the page with ID “txtNum1”</p>