Selenium WebDriver-actionchain模拟键盘操作
#encoding=utf-8
import unittest
import time
import chardet
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys class VisitSogouByIE(unittest.TestCase): def setUp(self):
#启动IE浏览器
#self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver")
#self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer")
self.driver = webdriver.Chrome(executable_path = "e:\\chromedriver")
#仅chrome和ie11的最新版本生效
def test_simulationCombinationKeys(self):
url = "http://www.baidu.com"
# 访问百度首页
self.driver.get(url)
# 将焦点切换到搜索输入框中
input = self.driver.find_element_by_id("kw")
input.send_keys(u"光荣之路")
time.sleep(2)
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').\
key_up(Keys.CONTROL).perform()
time.sleep(2)
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('x').\
key_up(Keys.CONTROL).perform()
self.driver.get(url)
self.driver.find_element_by_id("kw").click()
# 模拟Ctrl + V组合键,将从剪切板中获取到的内容粘贴到搜索输入框中
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('v').\
key_up(Keys.CONTROL).perform()
# 点击“百度一下”搜索按钮
self.driver.find_element_by_id('su').click()
time.sleep(3) def tearDown(self):
# 退出IE浏览器
self.driver.quit() if __name__ == '__main__':
unittest.main()
Selenium WebDriver-actionchain模拟键盘操作的更多相关文章
- selenium - webdriver - Keys类(键盘操作)
Keys()类提供了键盘上几乎所有按键的方法,这个类可用来模拟键盘上的按键,包括各种组合键,如 Ctrl+A, Ctrl+X,Ctrl+C, Ctrl+V 等等 from selenium impor ...
- Python+Selenium自动化-模拟键盘操作
Python+Selenium自动化-模拟键盘操作 0.导入键盘类Keys() selenium中的Keys()类提供了大部分的键盘操作方法:通过send_keys()方法来模拟键盘上的按键. # ...
- firefox下载文件弹出框之终极解决方案-vbs模拟键盘操作
由于近期一直被firefox的保存文件弹出框困扰,摸索尝试过几种方法,已有的方法可以跑通但是对对效果不太满意,因此一直在寻找合适的解决办法. 最近发现了也可以通过VBS来处理弹出框,速度也不错,其原理 ...
- 孤荷凌寒自学python第八十五天配置selenium并进行模拟浏览器操作1
孤荷凌寒自学python第八十五天配置selenium并进行模拟浏览器操作1 (完整学习过程屏幕记录视频地址在文末) 要模拟进行浏览器操作,只用requests是不行的,因此今天了解到有专门的解决方案 ...
- wshShell.SendKeys模拟键盘操作
Dim wshShellSet wshShell = CreateObject("Wscript.Shell")wshShell.SendKeys "{ENTER}&qu ...
- selenium webdriver(4)---模拟鼠标键盘操作
webdriver提供Actions来模拟鼠标悬浮.拖拽和键盘输入等操作,详细代码见org.openqa.selenium.interactions.Actions.本文通过几个实例来说明Action ...
- selenium模拟键盘操作
单键 /** * 模拟键盘回车事件 * @throws AWTException */ public void KeyEventEnter() throws AWTException { Robot ...
- Selenium 3----鼠标、键盘操作常用方法
[鼠标] 在 WebDriver 中, 关于鼠标操作的方法封装在 ActionChains 类中. ActionChains 类提供了鼠标操作的常用方法: perform(): 执行所有 Action ...
- 4. selenium中鼠标和键盘操作
一.鼠标操作 第一步:引入模块函数 from selenium.webdriver.common.action_chains import ActionChains 第二步:元素定位 element ...
随机推荐
- mui实现图片更换(暂未上传)
页面中有默认的图片,触发type为file的input时,更换图片,这个是mui移动端的项目,算了,不多说,开码 首先,先在html页面中设置样式,样式我就不给了,贴个布局 <div class ...
- 学习Linux的好网站
http://www.linuxcommand.org/ 很不错的学习shell和script的教程.包含:Learning the shell 和 writing shell scripts 两个内 ...
- 如何修改Ruby的gem源(gem sources)
Ruby环境下的gem sources地址默认是国外网络地址,所以在使用gem的过程中经常会出现找不到资源的Error.那么如何解决这种Error?方法很简单:要么就多次尝试执行gem命令,要么就修改 ...
- 自定义标签jsp2格式
在写自定义标签时候是不是感觉很烦啊,其实人家也是这样认为的,于是我们的jsp新的标准对标签进行了更改,使我们用起来更简单.到底哪里简单呢?看看代码再说咯: 还是老规矩,先上一个标签的逻辑类: 1. p ...
- 两个有序数列,求中间值 Median of Two Sorted Arrays
原题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ...
- 【转】在MAC下使用ISO制作Linux的安装USB盘
http://www.linuxidc.com/Linux/2013-04/82973.htm 在Mac环境下,将Linux的ISO镜像生成一个Linux的安装盘,和Linux下差不多,只是Mac下有 ...
- js中替换字符串
function formatStr(str){ str=str.replace(/\r\n/ig,"<br/>"); return str; } 要注意两点: 要使用 ...
- HTML5<header>元素
HTML5<header>元素 1.header元素描述了文档的头部区域,主要用于定义内容的介绍展示区域. 2.实例: <header> <h2>heder元素描述 ...
- c++作业:递归调用,例题4.5 求第五个人的年龄
递归调用,例题4.5 求第五个人的年龄 #include <iostream> using namespace std; int age(int num){ int a; ) a=; el ...
- const,static,extern,#define
一.const // 简单定义变量,可以修改变量的值 ; a = ; // const的用法 // 用法一: ; ; // 不允许修改,因为 const 修饰 b/c,指定 b/c 为常量!! // ...