常用接口说明
接口 | 描述 |
---|---|
click(on_element = None ) | 单击一个元素 |
double_click(on_element = None ) | 双击一个元素 |
move_by_offset(xoffset,yoffset | 将鼠标移动到当前鼠标位置的偏移处 |
move_to_element(to_element ) | 将鼠标移到元素的中间 |
move_to_element_with_offset(to_element,xoffset,yoffset ) | 将鼠标移动指定元素的偏移量 |
perform() | 执行所有存储的操作 |
样例
下面代码是模拟在百度上搜素python关键字
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
driver_path = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(executable_path=driver_path)
driver.get("https://www.baidu.com")
id = driver.find_element_by_id("su")
print(id.get_attribute("value"))
k = driver.find_element_by_id("kw")
k.send_keys("python")
Action = ActionChains(driver)
Action.move_to_element(id)
Action.click()
Action.perform()