相关的模块:
1.webDriverWait:显示等待针对元素必用
2.expeced_conditions 预期条件类(里面包含方法可以调用,用于显示等待)
3.NoSuchElementException用于隐式等待抛出异常
4.By 用于元素定位
主要的代码:
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys
driver=webdriver.Firefox()
driver.get("http://www.baidu.cn")
driver.find_element_by_css_selector("#kw").send_keys("Python")
sleep(2)
# 模拟手工 进行全选的操作
driver.find_element_by_css_selector("#kw").send_keys(Keys.CONTROL,"a")
sleep(2)
# 复制或者剪切
driver.find_element_by_css_selector("#kw").send_keys(Keys.CONTROL,"c")
# driver.find_element_by_css_selector("kw").send_keys(Keys.CONTROL,"x")
driver.get('http://www.sogou.com/')
sleep(2)
# 粘贴 操作
driver.find_element_by_css_selector(".sec-input").send_keys(Keys.CONTROL,"v")
sleep(2)
driver.find_element_by_css_selector("#stb").click()
sleep(2)
driver.quit()