python之一driver.find_element_by_xpath与driver.find_element(by, value)的区别

转载:https://www.cnblogs.com/songzhenhua/p/12902288.html

selenium有以下定位方式:

driver.find_element_by_id(‘id’)
driver.find_element_by_xpath('xpath')
driver.find_element_by_link_text('link_text')
driver.find_element_by_partial_link_text('partial_link_text')
driver.find_element_by_name('name')
driver.find_element_by_tag_name('tag_name')
driver.find_element_by_class_name('class_name')
driver.find_element_by_css_selector('css_selector')

  但我们看下源码:
Lib\site-packages\selenium\webdriver\remote
可以看到,上面那些定位方式,实际上都是调用的driver.find_element(by, value)

python之一driver.find_element_by_xpath与driver.find_element(by, value)的区别

 

python3.7\Lib\site-packages\selenium\webdriver\common

继续看源码,可以看到下面8种

ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"

 

python之一driver.find_element_by_xpath与driver.find_element(by, value)的区别

 

上一篇:Vue-cli


下一篇:如何优化selenium webdriver的执行速度