class By(object):
"""
Set of supported locator strategies.
"""
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"
3 使用方法
例如:
代码语言:python代码运行次数:0复制
driver.find_element(By.ID, "xx").click()
另一种写法:
代码语言:python代码运行次数:0复制
driver.find_element_by_id( "xx").click()
两种写法的区别,我们查看find_element_by_id的源码:
代码语言:python代码运行次数:0复制
def find_element_by_id(self, id_):
"""Finds an element by id.
:Args:
- id_ - The id of the element to be found.
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
element = driver.find_element_by_id('foo')
"""
return self.find_element(by=By.ID, value=id_)