 <p>The selector <code>#credentials.errors</code> looks for an element with the ID "credentials" and a class "errors", <em>not</em> an element with the ID "credentials.errors". The dot is being interpreted as the start of a class selector. In other words, it's equivalent to <code>.errors#credentials</code>, with both simple selectors swapped around.</p> <p><code>document.getElementById()</code> works because it simply takes a string as the input ID. It does not try to parse it as a compound selector.</p> <p>To correctly locate the element with an ID selector, you need to escape the dot:</p> <pre><code>driver.findElement(By.cssSelector("#credentials\\.errors")); </code></pre> <p>You can also use an attribute selector instead so you don't have to escape anything:</p> <pre><code>driver.findElement(By.cssSelector("[id='credentials.errors']")); </code></pre>