gpt4 book ai didi

java - 在 Selenium Webdriver 中,哪个在性能方面更好 Linktext 或 css?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:52:23 24 4
gpt4 key购买 nike

Selenium 中,最好使用定位器 ID 定位元素。

最小定位器是 XPath(如果我错了请纠正我)。

那么,人们应该使用定位器 来识别元素 是否有任何优先顺序或顺序?

最佳答案

这是在 https://stackoverflow.com/questions 上定位元素的不同方法的一些基准测试:

Chrome 52,驱动程序 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,驱动程序 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,驱动程序 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")

关于java - 在 Selenium Webdriver 中,哪个在性能方面更好 Linktext 或 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38716233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com