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 ...
 
随机推荐
- Pointer 指针
			
利用指针访问对象,指针指向一个对象,允许使用解引用符(操作符*)来访问对象 int ival = 42; int *p = &ival;//p存放变量ival的内存地址,p是指向变量ival的 ...
 - 再学IHanlder 类----------------关于Asp.net与iis原理网上看博客收获写一个验证码用一般处理程序记的好长时间前就写过不过现在再看有点不一样的感觉
			
建一个web网站 新建一般处理程序直接贴代码: using System;using System.Collections.Generic;using System.Linq;using System ...
 - 19.Consent视图制作
			
新建consentController 继承Controller并引用命名空间 给他一个get的Action Index 添加一个Index的View 新建一个ConsentViewModel 再新建 ...
 - 7.15实习培训日志 java题解
			
周末总结 本周主要学习了markdown,git,docker等工具的使用.在本周的学习中,初步了解了markdown,git,docker的使用.本周的静态博客部署中,对于怎么显示一个博客内容,有两 ...
 - linux jar 后台运行
			
在linux系统中可以利用nohup来执行任何命令,并把命令自动调到linux后台运行,不锁定当前ssh窗口,也不会被ctrl + c,alt + F4之类打断程序的动行.如: nohup java ...
 - CodeForces - 633D Fibonacci-ish 大数标记map+pair的使用
			
Fibonacci-ish Yash has recently learnt about the Fibonacci sequence and is very excited about it. He ...
 - Android 自定义ViewGroup 实战篇 -> 实现FlowLayout
			
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38352503 ,本文出自[张鸿洋的博客] 1.概述 上一篇已经基本给大家介绍了如 ...
 - Fenwick Tree / Binary Indexed Tree
			
Motivation: Given a 1D array of n elements. [2, 5, -1, 3, 6] range sum query: what's the sum from 2n ...
 - AndroidStudio常用快捷键
			
Alt+Insert:查找override函数 Alt+Enter:自动引包
 - Shaderlab blend
			
http://www.cnblogs.com/daxiaxiaohao/p/4059310.html 1.不透明度 当我们要将两个半透的纹理贴图到一个材质球上的时候就遇到混合的问题,由于前面的知识我们 ...