python selenium模拟滑动操作
selenium.webdriver提供了所有WebDriver的实现,目前支持FireFox、phantomjs、Chrome、Ie和Remote
quit()方法会退出浏览器,而close()方法只是关闭页面,但如果只有一个页面被打开,close()方法同样会退出浏览器
使用remote WebDriver
使用remote WebDriver之前,需要先启动selenium server,命令如下:
java -jar selenium-server-standalone-2.x.x.jar
selenium server运行之后会看到如下信息:
15:43:07.541 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
上面的信息指明了连接seleniumserver的地址http://127.0.0.1:4444/wd/hub,下面是实例代码:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities driver = webdriver.Remote( command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME) driver = webdriver.Remote( command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.OPERA) driver = webdriver.Remote( command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.HTMLUNITWITHJS)
Desiredcapabilities是字典类型,因此除了使用默认值,也可以重新定义字典的值,代码如下:
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities={'browserName':'htmlunit',
',
'javascriptEnabled':True})
send_keys(keys.RETURN) #键盘返回键
send_keys(Keys.ARROW_DOWN) #键盘向下的箭头
#coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains #引入ActionChains鼠标操作类
from selenium.webdriver.common.keys import Keys #引入keys类操作
import time
browser = webdriver.Chrome()
browser.get('http://www.baidu.com')
print '现在将浏览器最大化'
browser.maximize_window()
article = browser.find_element_by_link_text(u'周碧华:社科院出现内鬼意味着什么?')
ActionChains(browser).move_to_element(article).perform()#将鼠标移动到这里,但是这里不好用
ActionChains(browser).context_click(article).perform()
time.sleep(5)
browser.quit()
python selenium模拟滑动操作的更多相关文章
- python selenium鼠标滑动操作
先安装pyautogui: pip install pyautogui #coding=utf-8 import pyautogui from selenium import webdriver fr ...
- python+selenium模拟鼠标操作
from selenium.webdriver.common.action_chains import ActionChains #导入鼠标相关的包 ------------------------- ...
- 使用Python+Selenium模拟登录QQ空间
使用Python+Selenium模拟登录QQ空间爬QQ空间之类的页面时大多需要进行登录,研究QQ登录规则的话,得分析大量Javascript的加密解密,这绝对能掉好几斤头发.而现在有了seleniu ...
- python+selenium模拟京东登录后台
python+selenium模拟京东登录后台 import json from time import sleep from selenium import webdriver #from sele ...
- python selenium 基本常用操作
最近学习UI自动化,把一些常用的方法总结一下,方便自己以后查阅需要.因本人水平有限,有不对之处多多包涵!欢迎指正! 一.xpath模糊匹配定位元素 武林至尊,宝刀屠龙刀(xpath),倚天不出(css ...
- python selenium模拟登陆163邮箱。
selenium是可以模拟浏览器操作. 有些爬虫是异步加载的,通过爬取网页源码是得不到需要的内容.所以可以模拟浏览器去登陆该网站进行爬取操作. 需要安装selenium通过pip install xx ...
- selenium 模拟滑动解锁
来源:Selenium模拟JQuery滑动解锁 (selenium +Python ) 本文:selenium+Java package cn.gloryroad; import org.open ...
- python selenium鼠标键盘操作(ActionChains)
用selenium做自动化,有时候会遇到需要模拟鼠标操作才能进行的情况,比如单击.双击.点击鼠标右键.拖拽等等.而selenium给我们提供了一个类来处理这类事件--ActionChains sele ...
- selenium 鼠标滑动操作验证码
selenium 鼠标点击操作比较简单,这里就不介绍了,主要说一下鼠标滑动(按住并滑动),经常用于解决自动化操作的滑动验证码 下面举个简单的例子,比如这种验证码: 代码: div = driver.f ...
随机推荐
- nasm汇编一些需要注意的地方
经常用msam或tasm的童鞋一下转换到nasm下可能觉得不怎么适应,它们应该先去晓习一下gas的语法,然后就适应了-that's only a joke! :) section .data v101 ...
- .net framework 4 线程安全概述
线程安全:如果你的代码所在的进程中有多个线程在同时运行,而这些线程可能会同时运行这段代码.如果每次运行结果和单线程运行的结果是一样的,而且其他的变量的值也和预期的是一样的,就是线程安全的.早期的时候, ...
- angular4 ionic3 app
对于angular系列来说,从2到4仅仅是版本号的变更,绝大部分都是兼容的. 如果按照规范编写代码,一般来说是没有问题的. 学习angular4 快速入门参考 https://www.an ...
- MariaDB/MySQL用户和权限管理
本文目录: 1.权限验证 1.1 权限表 1.2 图解认证和权限分配的两个阶段 1.3 权限生效时机 2.用户管理 2.1 创建用户 2.2 create user和alter user 2.3 记录 ...
- Next Permutation 下一个排列
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- AOP事务解决方案和分布式事务方案
http://www.cnblogs.com/jianxuanbing/p/7242254.html http://www.cnblogs.com/jianxuanbing/p/7199457.htm ...
- Day14 JavaScript
区分: JavaScript和JAVA一点关系没有,是一门单独的语言.(浏览器就是JavaScript的解释器) JavaScript代码存在形式: #这些代码一般都是在<head>< ...
- Pycharm安装教程
1.下载PyQt 官方网站:http://www.riverbankcomputing.com/software/pyqt/download5 我的操作系统是64位的,安装的是Python3.4.3, ...
- Yii2数据接口
写接口之前先确认那你已经安装了Yii2的basic版或者advanced版,如果还没有,赶快去看这篇文章:composer安装Yii2. 现在默认你已经安装了basic版或者advanced版了,并且 ...
- 字符串转json以及获取域名的参数
本例将通过location.search来进行字符串拼接成json以及查询域名参数的value console.log(request('id')); function request(obj){ v ...