其他分享
首页 > 其他分享> > Selenium的键盘操作

Selenium的键盘操作

作者:互联网

from selenium import webdriver
from time import sleep
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
action = ActionChains(driver)
URL = r"C:\Users\I\Desktop\注册A.html"
driver.get(URL)

# 使用css的id定位,定位用户名,输入admin
ele = driver.find_element_by_css_selector("#userA")

# 键盘操作,删除
# ele.send_keys("admin")
# ele.send_keys(Keys.BACK_SPACE)

# 需求:键盘操作,复制用户名,粘贴到密码框,并清除
ele.send_keys("admin")
ele.send_keys(Keys.CONTROL, "a")
ele.send_keys(Keys.CONTROL, "c")

ele_pw = driver.find_element_by_css_selector("#passwordA")
ele_pw.send_keys(Keys.CONTROL, "v")
ele_pw.clear()

sleep(8)
driver.quit()

标签:keys,driver,Selenium,send,ele,键盘,Keys,import,操作
来源: https://www.cnblogs.com/sdr900/p/16227138.html