title: Selenium can't find element by id and xpath
body: <p>I read already all the other questions about this topic, there are a lot. I tried some but I do not find error in the code.</p>
  
  <p>I tried adding a timer too to wait for the page to load.</p>
  
  <p>Below the html code and the java:</p>
  
  <p>HTML:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form id="myform" method="get" action=""&gt;
      &lt;input type="hidden" name="something1" id="something1.1" /&gt;
      &lt;input type="hidden" name="something2" value="" /&gt;
   &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;Name: &lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;select name="name"&gt;
                  &lt;option selected="selected" value="1000"&gt;FirstNameOnly&lt;/option&gt;
              &lt;/select&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;Direction: &lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;select name="Direction"&gt;
                  &lt;option selected="selected" value=""&gt;Choose One&lt;/option&gt;
                  &lt;option value="UP"&gt;UP&lt;/option&gt;
              &lt;/select&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="2"&gt;&lt;label&gt;Time: &lt;/label&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;From: &lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" value="" name="from" id="id6"/&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;To: &lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" value="" name="to" id="id7"/&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;File type: &lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;span id="id8"&gt;
              &lt;input name="fileType" type="radio" checked="checked" value="0" id="id8-0"/&gt;&lt;label for="id8-0"&gt;Excel&lt;/label&gt;
              &lt;input name="fileType" type="radio" value="1" id="id8-1"/&gt;&lt;label for="id8-1"&gt;CSV&lt;/label&gt;
              &lt;/span&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;
              &lt;input type="submit" name="p::submit" id="id9" value="Preview"&gt;
              &lt;input type="submit" name="download" id="ida" value="Download"&gt;
          &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>JAVA:</p>
  
  <pre><code>public void HeadlessChromeStartDownload(){
  
      System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
  
      ChromeOptions options = new ChromeOptions();
      if (ValidateOS.isWindows()){
          options.setBinary("C:\\Users\\Juri\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe");
          System.out.println("Windows system");
      } else if (ValidateOS.isUnix()){
          options.setBinary("/path/to/chrome/not/yet/added");
      }
  
      options.addArguments("--headless --disable-gpu");
      ChromeDriver driver = new ChromeDriver(options);
  
      driver.get("http://localhost/that-test-page.html");
      //WebElement timer = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("id8-1")));
  
      WebElement select1 = driver.findElementByName("FirstNameOnly");
      Select field1 = new Select(select1);
      field1.selectByIndex(1);
  
      WebElement select2 = driver.findElementByName("Direction");
      Select field2 = new Select(select2);
      field2.selectByIndex(1);
  
      driver.findElementByName("from").sendKeys("21/06/2017");
  
      driver.findElementByName("to").sendKeys("22/06/2017");
  
      /*File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
      try {
          FileUtils.copyFile(scrFile, new File("C:\\screen1.jpg"));
          System.out.println("Screen saved");
      } catch (IOException e) { System.out.println("Screen NOT saved"); }
      */
  
      //driver.findElement(By.id("id8-1")).click();
      driver.findElement(By.xpath("//form[1]/input[6]")).click();
  
      //driver.findElementById("ida").click();
  
      driver.quit();
  }
  </code></pre>
  
  <p><strong>It really does not matter if I use:</strong></p>
  
  <pre><code>driver.findElement(By.id("id8-1")).click();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>driver.findElementById("id8-1").click();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>driver.findElement(By.xpath("//form[1]/input[6]")).click();
  </code></pre>
  
  <p>I can't get Selenium to click on that radio button.
  And the same goes for the rest of the code, in fact I used <code>findElementByName</code> which obviously is not the best choice.</p>
  
  <p>Thanks to anyone who knows what is wrong with this code!! (: (: </p>
  
  <h1>UPDATE1:</h1>
  
  <p>So, I can not explain what happened yesterday. The website I am trying to test was using <strong>id8-1</strong> for that radio button. Today it is <strong>id3-1</strong>, and both the solution with: <code>driver.findElement(By.cssSelector("input[value='1']")).click();</code>  or mine: <code>driver.findElement(By.id("id3-1")).click();</code> worked.</p>
  
  <p>I'm astonished. It was clearly 8 yesterday.
  Still, I do not know if using the cssSelector solution is the best, because I want to work with the IDs.
  I upvoted all the answers because all are useful but I wish to use IDs so I'm using my code.. In case of updates by your side I will choose it the one (: (:</p>
  
  <p>Thanks to all!!!</p>