from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
访问谷歌浏览器
driver=webdriver.Chrome()
访问地址
driver.get("")
最大窗口
driver.maximize_window()
time.sleep(1)
输入文字
ele=driver.find_element_by_xpath('//*[@id="kw"]')
ele.send_keys("英雄联盟")
ele.send_keys(Keys.BACKSPACE)
time.sleep(1)
全选
ele.send_keys(Keys.CONTROL,'a')
time.sleep(1)
剪切
ele.send_keys(Keys.CONTROL,'x')
time.sleep(1)
粘贴
ele.send_keys(Keys.CONTROL,'v')
悬停
from selenium import webdriver
悬停要用的包
from selenium.webdriver import ActionChains
import time
# 创建浏览器
driver = webdriver.Chrome()
调整浏览器尺寸
driver.maximize_window()
# 访问链接
driver.get("https://study.163.com/")
driver.find_element_by_xpath('//*[@id="ux-modal"]/div[3]/span').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="j-pclose"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="ux-modal"]/div[1]/a').click()
time.sleep(1)
悬停用法
ActionChains(driver).move_to_element(driver.find_element_by_xpath('//span[@class="arrow down ux-icon-caret-down"]')).perform()
# time.sleep(1)
ActionChains(driver).move_to_element(driver.find_element_by_xpath('(//a)[@title="生活兴趣"][2]')).perform()
# time.sleep(1)
driver.find_element_by_xpath('(//a)[@title="手工DIY"][2]').click()
# 保存快照
driver.save_screenshot("1.png")