title: Selenium Web Driver: findElement(By.name ..... and headless browser
body: <p>I'm trying to follow the Selenium Webdrive Tutorial </p>
  
  <p><a href="http://www.toolsqa.com/selenium-webdriver/headless-browser-testing-selenium-webdriver/" rel="nofollow">http://www.toolsqa.com/selenium-webdriver/headless-browser-testing-selenium-webdriver/</a></p>
  
  <p>There is a simple test, here you are the steps:</p>
  
  <ol>
  <li><p>Open webpage <a href="http://google.com" rel="nofollow">http://google.com</a></p></li>
  <li><p>Get the title of the page.</p></li>
  <li><p>Search for ‘Selenium’</p></li>
  <li><p>Check the title of the page again.</p></li>
  </ol>
  
  <p>Starting from the class code sample, here you are my code</p>
  
  <pre><code>package headlessBrowser;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.htmlunit.HtmlUnitDriver;
  
  public class TestOne {
  
  public static void main(String[] args) {
  
      // Declaring and initialising the HtmlUnitWebDriver
      HtmlUnitDriver unitDriver = new HtmlUnitDriver();
  
      // open google.com webpage
      unitDriver.get("http://google.com");
  
      System.out.println("Title of the page is -&gt; " + unitDriver.getTitle());
  
      // find the search edit box on the google page
      WebElement searchBox = unitDriver.findElement(By.name("q"));
  
      // type in Selenium
      searchBox.sendKeys("Selenium");
  
      // find the search button
      WebElement button = unitDriver.findElement(By.name("gbqfba"));
  
      // Click the button
      button.click();
  
      System.out.println("Title of the page is -&gt; " + unitDriver.getTitle());
  
     }
  }
  </code></pre>
  
  <p>Trying to execute it I've the following error</p>
  
  <pre><code>Title of the page is -&gt; 
  Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element with name: q
  </code></pre>
  
  <p>No page name is printed: ?????
  It seems that the "q" element in the page is not found. ????</p>
  
  <p>I've checked with Firebug and seems that the "q" element there is in the code (look for name="q" in the following snipplet code ...)</p>
  
  <pre><code>&lt;input spellcheck="false" dir="ltr" style="border: medium none; padding: 0px; margin: 0px; height: auto; width: 100%; background: transparent url(&amp;quot;data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D&amp;quot;) repeat scroll 0% 0%; position: absolute; z-index: 6; left: 0px; outline: medium none;" aria-autocomplete="both" role="combobox" aria-haspopup="false" class="gsfi" id="lst-ib" maxlength="2048" name="q" autocomplete="off" title="Cerca" value="" aria-label="Cerca" type="text"&gt;
  </code></pre>
  
  <p>I'm using Eclipse Luna on Windows 7</p>
  
  <p>Any suggestions? Thank you in advance ...</p>
  
  <p>Cesare</p>