selenuim 键盘操作
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
web_driver=webdriver.Firefox()
web_driver.get("https://baidu.com")
el=(By.ID,"kw")
WebDriverWait(web_driver,10,2).until(EC.presence_of_element_located(el))
el_se=web_driver.find_element(*el)
el_se.send_keys("selenium")
time.sleep(5)
el_se.send_keys(Keys.CONTROL,"a")
time.sleep(5)
el_se.send_keys(Keys.CONTROL,"c")
time.sleep(5)
el_se.clear()
time.sleep(5)
el_se.send_keys(Keys.CONTROL,"v")
time.sleep(5)
web_driver.quit()
drissionpage 键盘操作
问题 page.actions.key_down(DrissionKeys.CTRL_A) 报错 AttributeError: ‘tuple’ object has no attribute ‘upper’
未找到解决方案
from DrissionPage import WebPage
from DrissionPage.common import By as DrissionBy
from DrissionPage.common import Keys as DrissionKeys
page=WebPage("d")
page.get("https://baidu.com")
el=(DrissionBy.ID,"kw")
page.wait.eles_loaded(el,timeout=5)
el_se=page.ele(el)
el_se.input("drissionpage")
page.actions.key_down(DrissionKeys.CTRL_A)
time.sleep(5)
page.actions.key_down(DrissionKeys.CTRL_C)
time.sleep(5)
el_se.clear()
time.sleep(5)
page.actions.key_down(DrissionKeys.CTRL_V)
time.sleep(5)
page.quit()
selenuim 鼠标
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
driver=webdriver.Firefox()
driver.get("https://baidu.com")
time.sleep(5)
el=(By.ID,"s-usersetting-top")
el_se1=driver.find_element(*el)
#不管执行什么操作最后都需要perform
ActionChains(driver).move_to_element(el_se1).perform()
time.sleep(5)
el=(By.LINK_TEXT,"高级搜索")
el_se2=driver.find_element(*el)
el_se2.click()
time.sleep(5)
driver.quit()
drissionpage 鼠标
from DrissionPage import WebPage
from DrissionPage.common import By as DrissionBy
page=WebPage("d")
page.get("https://baidu.com")
el=(DrissionBy.ID,"s-usersetting-top")
el_se=page.ele(el)
page.actions.move_to(el_se)
time.sleep(5)
# el=(DrissionBy.LINK_TEXT,"高级搜索")
#<a href="//www.baidu.com/gaoji/advanced.html" target="_blank"><span class="set">高级搜索</span></a>
#这种的无法使用(DrissionBy.LINK_TEXT,"高级搜索") 去匹配
el=(DrissionBy.XPATH,'//*[@id="s-user-setting-menu"]/div/a[2]')
el_se2=page.ele(el)
# el_se2.click()
page.actions.click(el_se2)
time.sleep(5)
page.quit()