Reputation: 347
_driver.FindElement(By.CssSelector("[id='3_NewSiteMaintenanceButton']"));
=15.0s
_driver.FindElement(By.CssSelector("[id$='NewSiteMaintenanceButton']"));
=18.4s
_driver.FindElement(By.CssSelector("#3_NewSiteMaintenanceButton"));
NoSuchElementException : Unable to find element with css selector == #3_NewSiteMaintenanceButton
_driver.FindElement(By.Id("3_NewSiteMaintenanceButton"));
=12.58s
Chrome and FireFox complete the entire test in 4 and 6 seconds respectively, while IE takes 12-18 seconds to find a single DOM element. Why is IE so much slower, and how can I increase performance?
Upvotes: 2
Views: 243
Reputation: 723598
An ID selector cannot begin with a digit, because a CSS identifier cannot begin with a digit. If you had not quoted the value in your attribute selectors, they would both fail for the same reason (although it is strange that it results in a NoSuchElementException instead of something else, because technically the selector is invalid).
To use an ID selector, you need to escape the initial digit. If the digit is coming from a variable, you can still escape it separately, just place the escape immediately after the hash:
_driver.FindElement(By.CssSelector("#\\" + prefex + "_NewSiteMaintenanceButton"));
Upvotes: 6