python模拟人工滑动_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鼠标滑动操作

先安装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 ...

随机推荐

使用PHP将长文章分页

如何分页 手动分页:一般在编辑内容时加入特殊分页标记,如{pages},提交后,PHP程序会根据分页符处理分页,生成不同的静态页面.这种分页方法分页准确,但是需要人工手动添加分页符,工作量大. 自动分 ...

权限管理:(RBAC)

一般做正规的权限管理程序基本就是以下M表模式: 例1:在页面显示管理者的权限,并可以修改的管理界面 数据库表如下: 管理界面(附ajax):

python--Selectors模块/队列

Selectors模块/队列 一 Selectors模块 IO多路复用实现机制 Win: select Linux:select(效率低)  poll  epoll(最好)默认选择epoll sele ...

学JAVA第八天,今天用循环做了个好玩的东西

今天用for循环做了个打印矩形的图案 代码如下: package nf;class Kest{ public static void main(String args[]){ int a=30; in ...

不用写代码的框架 - RobotFramework+Eclispe环境安装篇

环境安装是学习任何一个新东西的第一步,这一步没走舒坦,那后面就没有心情走下去了. 引用名句:工欲善其事必先利其器!! Robotframework:一款 自动化测试框架. Eclipse:一款编辑工具 ...

DCL单例模式

我们第一次写的单例模式是下面这样的: public class Singleton { private static Singleton instance = null; public static ...

搭建SpringBoot+dubbo+zookeeper+maven框架(二)

上一篇文章是关于搭建SpringBoot+dubbo+zookeeper+maven框架的,但是里面的功能还不够完善,今天就日志管理方面做一些改善. 下了demo的网友可能会发现项目在启动时会有警告: ...

C# if else 使物体在X轴循环移动

if( transform.position.x > -15 && transform.rotation.y == 0 ) { //小鸟X轴反方向移动速度 transform.p ...

iOS中CGRectDividede中布局用法

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

UNIX环境编程学习笔记(11)——文件I/O之文件时间以及 utime 函数

lienhua342014-09-16 1 文件的时间 每个文件都有三个时间字段,如表 1 所示. 表 1: 文件的三个时间字段 说明 字段 st_atime 文件数据的最后访问时间 st_mtime ...

你可能感兴趣的:(python模拟人工滑动)