打印索引元素的文本属性
def print_list(coordinate_list):
print('当前项目地块数:', len(coordinate_list))
for i in range(0, len(coordinate_list)):
print(i)
print(coordinate_list[i].text)
看一下By支持的方法
class By:
"""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"
示例
element = driver.find_element(By.TAG_NAME,"html")
# 替换为您要检查的标签
attribute_value = element.get_attribute("data-theme") # 替换为您要获取的属性名称
# 打印属性值
print("html标签的属性值:", attribute_value)
CLASS_NAME、NAME、ID同理,以www.baidu.com为例