python
from selenium import webdriver
# 创建浏览器对象
path = 'files/chromedriver.exe'
browser = webdriver.Chrome(path)
# 访问地址
url = 'https://www.baidu.com'
browser.get(url)
input = browser.find_element_by_id('su')
- 获取元素属性
python
.get_attribute('class')
python
print(input.get_attribute('class'))
- 获取标签名
python
.tag_name
python
print(input.tag_name)
- 获取元素文本
python
.text
python
a = browser.find_element_by_link_text('hao123')
print(a.text)