标签:key sleep 回车 class com source targe driver click
Selenium提供ActionChains类中
from selenium.webdriver.common.action_chains import ActionChains
鼠标操作的常用方法:
操作 | 方法 |
---|---|
右击 | context_click() |
双击 | double_click() |
拖动 | drag_and_drop(source,target) |
悬停 | move_to_element() |
perform() | 执行所有的ActionChains中存储的行为 |
例:
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
chrome = webdriver.Chrome()
chrome.maximize_window()
chrome.get(‘https://www.baidu.com‘)
test = chrome.find_element_by_id(‘kw‘)
ActionChains(chrome).context_click(test).perform()
time.sleep(5)
Selenium提供Keys类中
鼠标操作的常用方法:
操作 | 方法 |
---|---|
输入 | send_keys() |
删除键 | send_keys(Keys.BACK_SPACE) |
空格键 | send_keys(Keys.SPACE) |
制表键 | send_keys(Keys.TAB) |
回退键 | send_keys(Keys.ESCAPE) |
回车键 | send_keys(Keys.ENTER) |
ctrl+A | send_keys(Keys.CONTROL,‘a‘) |
ctrl+C | send_keys(Keys.CONTROL,‘c‘) |
ctrl+X | send_keys(Keys.CONTROL,‘x‘) |
ctrl+V | send_keys(Keys.CONTROL,‘v‘) |
ctrl+F1 | send_keys(Keys.CONTROL,‘F1‘) |
... | ... |
ctrl+F12 | send_keys(Keys.CONTROL,‘F12‘) |
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
chrome = webdriver.Chrome()
chrome.maximize_window()
chrome.get(‘https://www.baidu.com‘)
test = chrome.find_element_by_id(‘kw‘)
#输入
test.send_keys(‘selenium‘)
#退格(删除)
test.send_keys(Keys.BACK_SPACE)
#CTRL+A
test.send_keys(Keys.CONTROL,‘a‘)
#CTRL+C
test.send_keys(Keys.CONTROL,‘c‘)
#CTRL+V
test.send_keys(Keys.CONTROL,‘v‘)
#回车
test.send_keys(Keys.ENTER)
time.sleep(5)
标签:key sleep 回车 class com source targe driver click
原文地址:https://www.cnblogs.com/jingxindeyi/p/13058246.html