Python教程

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

本文主要是介绍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)

 

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)的区别的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!