Selenium 入門到精通系列python
PS:鼠標右鍵、鼠標懸停、鍵盤操做方法web
#!/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()