Here is a little benchmark of different methods to locate an element on https://stackoverflow.com/questions :
Chrome 52, driver 2.22
15 ms for execute_script("return [].find.call(document.getElementsByTagName('a'), function(e){return e.textContent.trim() == 'Physics'});")
15 ms for find_element_by_css_selector("#footer-sites > table > tbody > tr:nth-child(2) > td:nth-child(7) > ol > li:nth-child(2) > a")
15 ms for find_element_by_css_selector("[title='go to page 2']")
15 ms for find_element_by_xpath("//*[@id='footer-sites']/table/tbody/tr[2]/td[7]/ol/li[3]/a")
16 ms for find_element_by_class_name("top-footer-links")
16 ms for find_element_by_css_selector("a[href$='math.stackexchange.com']")
16 ms for find_element_by_id("footer-sites")
16 ms for find_element_by_name("q")
16 ms for find_element_by_xpath("//a[text()='Ask Ubuntu']")
31 ms for find_element_by_xpath("//*[normalize-space(.)='Game Development']")
311 ms for find_element_by_link_text("Area 51")
343 ms for find_element_by_partial_link_text("Stack Apps")
Firefox 2.47, driver 2.53.0
16 ms for find_element_by_class_name("top-footer-links")
16 ms for find_element_by_css_selector("#footer-sites > table > tbody > tr:nth-child(2) > td:nth-child(7) > ol > li:nth-child(2) > a")
16 ms for find_element_by_css_selector("a[href$='math.stackexchange.com']")
16 ms for find_element_by_id("footer-sites")
16 ms for find_element_by_name("q")
23 ms for execute_script("return [].find.call(document.getElementsByTagName('a'), function(e){return e.textContent.trim() == 'Physics'});")
23 ms for find_element_by_css_selector("[title='go to page 2']")
47 ms for find_element_by_xpath("//*[@id='footer-sites']/table/tbody/tr[2]/td[7]/ol/li[3]/a")
47 ms for find_element_by_xpath("//a[text()='Ask Ubuntu']")
62 ms for find_element_by_xpath("//*[normalize-space(.)='Game Development']")
1625 ms for find_element_by_link_text("Area 51")
1726 ms for find_element_by_partial_link_text("Stack Apps")
Internet Explorer 11, driver 2.53.1
77 ms for find_element_by_name("q")
78 ms for execute_script("return [].find.call(document.getElementsByTagName('a'), function(e){return e.textContent.trim() == 'Physics'});")
78 ms for find_element_by_class_name("top-footer-links")
78 ms for find_element_by_id("footer-sites")
93 ms for find_element_by_xpath("//*[@id='footer-sites']/table/tbody/tr[2]/td[7]/ol/li[3]/a")
108 ms for find_element_by_xpath("//a[text()='Ask Ubuntu']")
109 ms for find_element_by_css_selector("#footer-sites > table > tbody > tr:nth-child(2) > td:nth-child(7) > ol > li:nth-child(2) > a")
125 ms for find_element_by_css_selector("[title='go to page 2']")
125 ms for find_element_by_css_selector("a[href$='math.stackexchange.com']")
140 ms for find_element_by_xpath("//*[normalize-space(.)='Game Development']")
801 ms for find_element_by_link_text("Area 51")
812 ms for find_element_by_partial_link_text("Stack Apps")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…