org.openqa.selenium.NoSuchElementException error in IE but the same code works fine in Chrome and Firefox
This error message...
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #mod\-login\-username
...implies that the InternetExplorerDriver was unable to locate any element as per the Locator Strategy you have used.
Reason
As you have mentioned the same code works using ChromeDirver/Chrome and GeckoDriver/Firefox, it is worth to mention that different Browser Engine renders the HTML DOM differently. So brittle Locator Strategies may not work across all the browsers.
As per your question, script showing the error of "Unable to find element with css selector ..." as I have only used id
it is again worth to mention as per WebDriver W3C Editor's Draft the preferred Locator Strategies enlisted are as follows :
"css selector"
: CSS selector"link text"
: Link text selector"partial link text"
: Partial link text selector"tag name"
: Tag name"xpath"
: XPath selector
Snapshot :
A change was propagated through the respective client specific bindings. For the Selenium-Java
clients here is the client code where internally the Locator Strategies based on id
, and name
are internally converted to equivalent css selector through a switchcase as follows :
switch (using) { case "class name": toReturn.put("using", "css selector"); toReturn.put("value", "." + cssEscape(value)); break; case "id": toReturn.put("using", "css selector"); toReturn.put("value", "#" + cssEscape(value)); break; case "link text": // Do nothing break; case "name": toReturn.put("using", "css selector"); toReturn.put("value", "*[name='" + value + "']"); break; case "partial link text": // Do nothing break; case "tag name": toReturn.put("using", "css selector"); toReturn.put("value", cssEscape(value)); break; case "xpath": // Do nothing break; } return toReturn;
Snapshot :
Hence though you provide:
(By.id("mod-login-username"))
Error shows:
Unable to find element with css selector == #mod\-login\-username