1.代码实现

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import UnexpectedAlertPresentException
from time import sleep driver= webdriver.Ie()
driver.get('https://www.helloweba.net/demo/2017/unlock/')
driver.implicitly_wait(5) dragger = driver.find_elements_by_class_name('slide-to-unlock-handle')[0] #错误为:find_element_by_class_name action = ActionChains(driver) action.click_and_hold(dragger).perform() #鼠标左键按住不放 for index in range(200):
try:
action.move_by_offset(2,0).perform() #平行移动鼠标
except UnexpectedAlertPresentException:
break
action.reset_actions()
sleep(0.1) #等待停顿时间 sucess_text = driver.switch_to.alert.text
print(sucess_text) #打印警告框提示 sleep(5) driver.quit()

2.易错点:find_elements_by_class_name才是正确,当输入为find_element_by_class_name时,运行则报错:TypeError: 'WebElement' object does not support indexing

3.代码解释

(1)driver.find_elements_by_class_name("slide-to-unlock-handle")[0]==先通过class属性找到所有的里面的第一个

(2)click_and_hold()     ==对滑块按下鼠标左键

(3)move_by_offset()  ==通过for循环动滑块的位置,move_by_offset()方法第一个参数是X轴,第二个参数是Y轴,单位为像素。因为是平行移动,所以Y设置为0。 X每次移动两2个像素。每次循环休眠0.1秒,时间间隔越小,移动越顺滑.

15.Selenium+Python滑动解锁小案例的更多相关文章

  1. selenium 模拟滑动解锁

    来源:Selenium模拟JQuery滑动解锁   (selenium +Python ) 本文:selenium+Java package cn.gloryroad; import org.open ...

  2. Python:通过一个小案例深入理解IO多路复用

    通过一个小案例深入理解IO多路复用 假如我们现在有这样一个普通的需求,写一个简单的爬虫来爬取校花网的主页 import requests import time start = time.time() ...

  3. selenium+python自动化之登录案例

    一.登录 1.先打开浏览器 2.打开论坛主页:http://www.hordehome.com/ 3.查找元素之前可以先设置元素等待:implicitly_wait() 4.点登录按钮,弹出登录框 5 ...

  4. Python的应用小案例

    1.python统计文本中每个单词出现的次数: #coding=utf-8__author__ = 'zcg' import collectionsimport os with open('abc.t ...

  5. Python Django 实用小案例2

    动态导入模块 Django返回序列化数据  动态导入模块 在Django里面,经常会看到一些方法或者类是动态导入,尤其是以settings文件为代表,经常把一些类放在里面动态调配,比如随便拿Djang ...

  6. python 客户端点对点通信小案例

    点对点通讯分为客户端和服务器,多个客户端通过服务器进行信息的交流 服务器端代码  service端 #!/usr/bin/env python # -*- coding:utf-8 -*- impor ...

  7. 6.Python使用Pandas小案例

    1.使用以下命令引入Pandas和xlrd,引入成功后在pycharm的setting导入即可使用(pip3是由于个人python版本为3.6)==在dos命令行输入以下信息 pip3 install ...

  8. Turtle绘图——python简单上手小案例

    Turtle绘图 Turtle模块提供了在二维平面上移动的环境. Turtle可以实现位置.航向和各种可能的状态和动作. import turtle as tu roo = tu.Turtle() # ...

  9. python 之 Django 小案例

    一, F  Q # F 使用查询条件的值 # # from django.db.models import F # models.Tb1.objects.update(num=F('num')+1) ...

随机推荐

  1. [算法]Plus One

    Question: Given a non-negative number represented as an array of digits, plus one to the number. The ...

  2. 一个线程知识点, 一个MongoDB的知识点

    //WINForm窗体中切换前后台线程执行任务: protected void RunOnUI(Action action) { Invoke(action); } protected void Ru ...

  3. LeetCode——Max Consecutive Ones

    LeetCode--Max Consecutive Ones Question Given a binary array, find the maximum number of consecutive ...

  4. HTML常用标签——思维导图

    如图 思维导图图片链接 http://www.edrawsoft.cn/viewer/public/s/38d99149304484

  5. PAT1076. Forwards on Weibo (30)

    使用DFS出现超时,改成bfs DFS #include <iostream> #include <vector> #include <set> using nam ...

  6. python urllib2库的简单总结

    urllib2的简单介绍参考网址:http://www.voidspace.org.uk/python/articles/urllib2.shtml Fetching URLsThe simplest ...

  7. WPF 通过 CommandParameter 传递当前窗体到 ViewModel

    在应用 Command 模式中,需要在View上点击 一个按钮,需要将当前窗体作为参数传递为 command 两种方式传递当前窗体1.通过窗体名称(假设窗体名称为 ThisWindow)   < ...

  8. 遍历jsonArray和jsonObject

    遍历jsonArray String str = "[{name:'a',value:'aa'},{name:'b',value:'bb'},{name:'c',value:'cc'}]&q ...

  9. hdu1845

    题解: 只要输出n/2即可 代码: #include<cstdio> #include<cmath> #include<cstring> #include<a ...

  10. redis memcache rabbitMQ

    Python之路[第九篇]:Python操作 RabbitMQ.Redis.Memcache.SQLAlchemy Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动 ...