Which Selenium WebDriver locator is faster?

driver.find_element(:id, "search")
driver.find_element(:id, "modules_appointment_checkbox")
driver.find_element(:id, "terminology_human_resource")
driver.find_element(:id, "booking_interval_between_bookings")
driver.find_element(:id, "booking_max_client_distance")
driver.find_element(:id, "constraints_member_min_time_allowed_for_client_cancellation")
driver.find_element(:id, "save_preferences_button")
driver.find_element(:name, "search")
driver.find_element(:name, "modules[appointment]")
driver.find_element(:name, "terminology[human_resource]")
driver.find_element(:name, "booking[interval_between_bookings]")
driver.find_element(:name, "booking[max_client_distance]")
driver.find_element(:name, "constraints[member_min_time_allowed_for_client_cancellation]")
driver.find_element(:name, "commit")
driver.find_element(:xpath, "//input[@type='search']")
driver.find_element(:xpath, "//input[@type='checkbox' and @name='modules[appointment]']")
driver.find_element(:xpath, "//input[@type='text' and @name='terminology[human_resource]']")
driver.find_element(:xpath, "//select[@name='booking[interval_between_bookings]']")
driver.find_element(:xpath, "//input[@type='number' and @name='booking[max_client_distance]']")
driver.find_element(:xpath, "//input[@type='number' and @name='constraints[member_min_time_allowed_for_client_cancellation]']")
driver.find_element(:xpath, "//input[@type='submit' and @value='Save']")
driver.find_element(:css, "input#search")
driver.find_element(:css, "input#modules_appointment_checkbox")
driver.find_element(:css, "input#terminology_human_resource")
driver.find_element(:css, "select#booking_interval_between_bookings")
driver.find_element(:css, "input#booking_max_client_distance")
driver.find_element(:css, "input#constraints_member_min_time_allowed_for_client_cancellation")
driver.find_element(:css, "input#save_preferences_button")
ID:     39 ms
Name: 38 ms
XPath: 40 ms
CSS: 36 ms
ID:    346 loops
Name: 390 loops
XPath: 384 loops
CSS: 396 loops
ID:    392 loops
Name: 430 loops
XPath: 419 loops
CSS: 454 loops
driver.find_element(:id, "username").send_keys("zz")
Unable to locate element: {“method”:”css selector”,”selector”:”#zz"}

Award-winning software developer, test automation & CT coach, author, and speaker. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store