selenium自动化-获取元素的属性

# coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
time.sleep(2)
title = driver.title
print(title)
text = driver.find_element_by_id("setf").text
print(text)
# 获取元素的标签
tag = driver.find_element_by_id("kw").tag_name
print(tag)
# 获取元素的其它属性
name = driver.find_element_by_id("kw").get_attribute("class")
print(name)
# 获取输入框的内容
driver.find_element_by_id("kw").send_keys("yoyoketang")
value = driver.find_element_by_id("kw").get_attribute("value")
print(value)
# 获取浏览器名称
print(driver.name)

 

结果:

C:\Users\jelena.zhao\AppData\Local\Programs\Python\Python36\python3.exe E:/pythonscripts/study/test1/test.py
百度一下,你就知道
把百度设为主页
input
s_ipt
yoyoketang
chrome

Process finished with exit code 0

你可能感兴趣的:(selenium自动化)