Selenium 入门到精通系列
PS:鼠标右键、鼠标悬停、键盘操作方法
例子
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2019-04-23 16:12:33
# @Author : BenLam
# @Link : https://www.cnblogs.com/BenLam/
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
driver=webdriver.Firefox()
driver.get("http://www.baidu.com/")
right=size=driver.find_element_by_id("kw")
#鼠标右键
ActionChains(driver).context_click(right).perform()
halt=driver.find_element_by_class_name("bri")
#鼠标悬停
ActionChains(driver).move_to_element(halt).perform()
driver.find_element_by_id("kw").send_keys("Selenium ")
#删除空格
driver.find_element_by_id("kw").send_keys(Keys.BACK_SPACE)
#加入空格
driver.find_element_by_id("kw").send_keys(Keys.SPACE)
driver.find_element_by_id("kw").send_keys("TEST")
#全选内容
driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'a')
#剪切内容
driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'x')
#粘贴内容
driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'v')
#回车即可
driver.find_element_by_id("kw").send_keys(Keys.ENTER)
driver.quit()