Python3+Selenium3+webdriver学习笔记5(模拟常用键盘和鼠标事件)
#!/usr/bin/env python
# -*- coding:utf-8 -*- from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains import time,os # about:addons 火狐浏览器安装组件,访问的地址 # <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
# <input type="submit" value="百度一下" id="su" class="btn self-btn bg s_btn">
#id
keys="selenium自动化"
delay=3
url="https://www.baidu.com/"
driver=webdriver.Firefox() driver.get(url) #等待delay秒
driver.implicitly_wait(delay) #输入字符串
driver.find_element_by_id("kw").send_keys(keys) #清空输入的内容
driver.find_element_by_id("kw").clear() #鼠标左键点击
driver.find_element_by_id("su").click() driver.find_element_by_id("kw").send_keys(keys) #模拟回车提交表单
driver.find_element_by_id("kw").submit() driver.find_element_by_id("kw").send_keys(Keys.ENTER) #复制 粘贴 全选 剪切 制表键 f11~f12
driver.find_element_by_id("kw").send_keys(keys,Keys.CONTROL,'c') driver.find_element_by_id("kw").send_keys(keys,Keys.CONTROL,'v') driver.find_element_by_id("kw").send_keys(keys,Keys.CONTROL,'a') driver.find_element_by_id("kw").send_keys(keys,Keys.CONTROL,'x') driver.find_element_by_id("kw").send_keys(Keys.TAB) driver.find_element_by_id("kw").send_keys(Keys.F1) #执行ActionChains中的所有行为
source=driver.find_element_by_link_text("设置")
target=driver.find_element_by_link_text("新闻") # 鼠标悬停
ActionChains(driver).move_to_element(source).perform() # 右击鼠标
ActionChains(driver).context_click(source).perform() # 双击鼠标
ActionChains(driver).double_click(source).perform() #鼠标移动到另一个位置
ActionChains(driver).drag_and_drop(source,target).perform() # 鼠标左键
ActionChains(driver).click_and_hold(source).perform() #等待delay秒
time.sleep(delay) driver.quit()
Python3+Selenium3+webdriver学习笔记5(模拟常用键盘和鼠标事件)的更多相关文章
- Python3+Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )
!/usr/bin/env python -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )'''from selenium im ...
- Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)'''from sel ...
- Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...
- Python3+Selenium3+webdriver学习笔记11(cookie处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记11(cookie处理)'''from selenium im ...
- Python3+Selenium3+webdriver学习笔记10(元素属性、页面源码)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记10(元素属性.页面源码)'''from selenium i ...
- Python3+Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)'''from seleni ...
- Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...
- Python3+Selenium3+webdriver学习笔记7(选择多链接的结果、iframe、下拉框)
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...
- Python3+Selenium3+webdriver学习笔记6(多窗口切换处理)
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...
随机推荐
- [poj3107/poj2378]Godfather/Tree Cutting树形dp
题意:求树的重心(删除该点后子树最大的最小) 解题关键:想树的结构,删去某个点后只剩下它的子树和原树-此树所形成的数,然后第一次dp求每个子树的节点个数,第二次dp求解答案即可. 此题一开始一直T,后 ...
- [hdu4812]D Tree(点分治)
题意:问有多少条路径,符合路径上所有节点的权值乘积模1000003等于k. 解题关键:预处理阶乘逆元,然后通过hash和树形dp$O(1)$的判定乘积存在问题,注意此道题是如何处理路径保证不重复的,具 ...
- Hashtable源码剖析
Hashtable简介 Hashtable同样是基于哈希表实现的,同样每个元素是一个key-value对,其内部也是通过单链表解决冲突问题,容量不足(超过了阀值)时,同样会自动增长. Hashtabl ...
- ASP.NET in C#,ClientScript.RegisterStartupScript与ClientScript.RegisterClientScriptBlock用法之己见
ClientScript.RegisterStartupScript:http://msdn.microsoft.com/zh-cn/library/system.web.ui.clientscrip ...
- LeetCode: 389 Find the Difference(easy)
题目: Given two strings s and t which consist of only lowercase letters. String t is generated by rand ...
- 数据库路由中间件MyCat - 使用篇(6)
此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 配置MyCat 4. 配置schema.xml schema.xml里面管理着MyCat的逻辑库.表,每张表 ...
- 315. Count of Smaller Numbers After Self(Fenwick Tree)
You are given an integer array nums and you have to return a new counts array. The counts array has ...
- HyperLedger Fabric 多机部署(一)
本文参考:http://www.lijiaocn.com/%E9%A1%B9%E7%9B%AE/2018/04/26/hyperledger-fabric-deploy.html 学习. 1.准备工 ...
- 洛谷P3608 [USACO17JAN]Balanced Photo平衡的照片
P3608 [USACO17JAN]Balanced Photo平衡的照片 题目描述 Farmer John is arranging his NN cows in a line to take a ...
- 基于testcontainers的现代化集成测试进阶之路
大型的软件工程项目除了大量的产品级代码外必不可少的还有大量的自动化测试.自动化测试包含从前端到后端甚至到产品线上不同模块和环境的各种类型的测试.一个比较经典的关于自动化测试分布的理论就是测试金字塔,是 ...