python selenium2 模拟点击+拖动 测试对象 58同城验证码

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# @Time    : 2019/12/5 17:30
# @Author  : shenghao/[email protected]
‘‘‘test with selenium‘s move‘‘‘
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import cv2 as cv
import time, datetime, random
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.touch_actions import TouchActions
from selenium.webdriver.common.keys import Keys
from PIL import Image
import requests
from io import BytesIO
import cv2, time, sys
import matplotlib.pyplot as plt
import numpy as np

class selenium_2_move(object):
    def __init__(self):
        self.headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36"}
        chrome_option = webdriver.ChromeOptions()
        self.driver = webdriver.Chrome(executable_path="C:\Program Files\Python37\chromedriver.exe",
                                       chrome_options=chrome_option)
        self.driver.set_window_size(1440, 900)

    def visit_index(self):
        self.driver.get(
            "https://callback.58.com/antibot/verifycode?serialId=62cbf64a21ab4d309e722680c623a4e4_31ec33353c0648b7a5c97b1f2fb35976&code=22&sign=e6760461fc971994a2f3809ff536fbe9&namespace=anjuke_zufang_pc&url=.zu.anjuke.com%2Ffangyuan%2F1206610285371393%3Fisauction%3D1%26shangquan_id%3D1846")
        try:
            click_status = WebDriverWait(self.driver, 5, 1).until(
                EC.element_to_be_clickable((By.XPATH, "//div[@class = ‘code_num‘]/input"))).click()
            time.sleep(1)
            self.analog_drag()
        except:
            pass

    def analog_drag(self):
        ‘‘‘//div[@class = ‘dvc-slider__handler‘]  button position‘‘‘
        element = self.driver.find_element_by_xpath("//div[@class = ‘dvc-slider__handler‘]")
        if element:
            ActionChains(self.driver).click_and_hold(on_element=element).perform()
            ActionChains(self.driver).move_by_offset(xoffset=100, yoffset=0).perform()
            time.sleep(0.3)
            ActionChains(self.driver).move_by_offset(xoffset=-8, yoffset=0).perform()
            time.sleep(0.3)
            ActionChains(self.driver).move_by_offset(xoffset=-8, yoffset=0).perform()
            time.sleep(2)
            self.driver.close()

if __name__ == ‘__main__‘:
    h = selenium_2_move()
    h.visit_index()

原文地址:https://www.cnblogs.com/tnsay/p/12009938.html

时间: 2024-07-30 19:28:43

python selenium2 模拟点击+拖动 测试对象 58同城验证码的相关文章

python selenium3 模拟点击+拖动+保存验证码 测试对象 58同城验证码

#!/usr/bin/python # -*- coding: UTF-8 -*- # @Time : 2019/12/5 17:30 # @Author : shenghao/[email protected] '''test with selenium's move''' from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.

python selenium4 模拟点击+拖动+保存验证码 测试对象+以验证码的返回ID保存命名 58同城验证码

#!/usr/bin/python # -*- coding: UTF-8 -*- # @Time : 2019/12/5 17:30 # @Author : shenghao/[email protected] '''test with selenium's move''' from builtins import print from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWa

python selenium5 模拟点击+拖动+按照指定相对坐标拖动 58同城验证码

#!/usr/bin/python # -*- coding: UTF-8 -*- # @Time : 2019年12月9日11:41:08 # @Author : shenghao/[email protected] '''test with selenium's move by x,y''' from builtins import print from selenium import webdriver from selenium.webdriver.support.ui import W

如何使用python来模拟鼠标点击(将通过实例自动化模拟在360浏览器中自动搜索"python")

一.准备工作: 安装pywin32,后面开发需要pywin32的支持,否则无法完成与windows层面相关的操作. pywin32的具体安装及注意事项: 1.整体开发环境: 基于windows7操作系统; 提前安装python(因为篇幅问题,在此不详细讲解python环境的安装,大家可以自备楼梯): 大家可以在cmd中测试下python环境是否安装好: 大家可以看到我电脑上已经安装好了Python,并显示版本与是V 3.6.2. 注:自己电脑上的Python版本号一定要知道,后面安装pywin3

Android---Monkey指令进行压力测试实例(模拟点击)

我们在做安卓APP测试的时候,经常会用到Monkey指令来模拟对APP的点击操作,从而达 到多次点击的效果,比如连续点击1W次,看看APP的运行情况.下面呢我就给大家介绍下 用Monkey指令模拟点击APP的的方法. 下载好adb文件,我这里是已经有了,然后解压到自己的某个路径(随意,不强 制放在C盘目录下),我这里放在了D盘 设置好adb的环境变量: 通过cmd验证是否安装成功,输入adb shell,成功的话会显示如下: 我这手机在充电模式,这样显示了.开机后不会有下面的error信息. 在

js javascript 模拟点击 超级链接点击 转

转自:http://mo2g.com/view/42/ 我尝试过多次用jQuery模拟用户点击a标签的功能,但都没有成功,并且困扰了很久.前段时间的一次发呆,冒出了新的想法,于是就动手进行了测试. 先看下边的代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <html> <head> <meta charset="UTF-8"> <title>磨途歌-A标签测试1</tit

第2章2节《MonkeyRunner源码剖析》了解你的测试对象: NotePad窗口Activity之NotesList简介(原创)

天地会珠海分舵注:本来这一系列是准备出一本书的,详情请见早前博文"寻求合作伙伴编写<深入理解 MonkeyRunner>书籍".但因为诸多原因,没有如愿.所以这里把草稿分享出来,所以错误在所难免.有需要的就参考下吧,转发的话还请保留每篇文章结尾的出处等信息. NotePad窗口Activity之NotesList简介 上一节我们简要描述了测试对象NotePad的主要功能模块,那么这一节开始我们就会对每个模块进行相应的阐述,这样读者就算没有真正去安装和玩过这个应用也不会影响大

爬虫之动态HTML处理(Selenium与PhantomJS )动态页面模拟点击

动态页面模拟点击 #!/usr/bin/env python # -*- coding:utf-8 -*- # python的测试模块 import unittest from selenium import webdriver from bs4 import BeautifulSoup class douyuSelenium(unittest.TestCase): # 初始化方法 def setUp(self): self.driver = webdriver.PhantomJS() #具体的

使用python selenium-webdriver模拟博客园登录

初学python,最近在抱着虫师的python+selenium自动化的书看,也尝试写个登录功能的验证2333 code:########################## #使用python selenium-webdriver #模拟博客园的登录流程 #首页--登录页面--跳转回首页--检查--退出登录恢复环境 ########################### from selenium import webdriver import time import sys url_cnbl