title: How to look for text via XPath using Selenium for C#?
body: <p>Im trying to achieve checking for the text &quot;In stock.&quot;, via a XPath query, however my XPath variable elementInStock returns a ID, and it looks like its not finding the text &quot;In stock.&quot;, from the URL <a href="https://www.amazon.co.uk/dp/B08H96W864/ref=twister_B08J4RCVXW?_encoding=UTF8&amp;th=1" rel="nofollow noreferrer">https://www.amazon.co.uk/dp/B08H96W864/ref=twister_B08J4RCVXW?_encoding=UTF8&amp;th=1</a></p>
  <p>Would appreciate some help how to find the text &quot;In stock.&quot; and do the Console.WriteLine(&quot;HEYYYY&quot;);</p>
  <p>if text &quot;In stock.&quot; not found then keep go to the while loop in mu code, my logic does not even go to the while loop if XPATH is null.</p>
  <p>Please advise.</p>
  <pre><code>class Program
      {
          static void Main(string[] args)
          {
  
              IWebDriver driver = new ChromeDriver();
  
              //Navigate to
              driver.Navigate().GoToUrl(&quot;https://www.amazon.co.uk/dp/B08H96W864/ref=twister_B08J4RCVXW?_encoding=UTF8&amp;th=1&quot;);
  
              driver.Manage().Window.Maximize();
  
  
              IWebElement elementInStock = driver.FindElement(By.XPath(&quot;/html/body/div[2]/div[2]/div[5]/div[4]/div[4]/div[18]&quot;));
  
              
  
              if (elementInStock != null)
              {
                  Console.WriteLine(&quot;HEYYYY&quot;);
              }
  
              else if (elementInStock == null)
                  {
                      int counter = 0;
  
                      while (counter &lt; 10)
                      {
  
                          Thread.Sleep(2500);
  
                          driver.Navigate().Refresh();
  
                      }
                  }
  
  
              }
          }
      }
  </code></pre>