zoukankan      html  css  js  c++  java
  • python selenium2 模拟点击+拖动 测试对象 58同城验证码

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    # @Time    : 2019/12/5 17:30
    # @Author  : shenghao/10347899@qq.com
    '''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 FilesPython37chromedriver.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()
  • 相关阅读:
    Android_listview设置每条信息的间距
    Android实现ListView或GridView首行/尾行距离屏幕边缘距离
    实现类似微信的延迟加载的Fragment——LazyFragment
    struts2的Action该方法不能去
    (工具)source insight高速增加时间代码
    猫学习IOS(十五)UI以前的热的打砖块游戏
    java语言内部类和匿名内部类
    JVM截至多少线程可以创建: unable to create new native thread
    linux下一个Oracle11g RAC建立(八)
    转基因小麦--主题在农业科技的最前沿
  • 原文地址:https://www.cnblogs.com/tnsay/p/12009938.html
Copyright © 2011-2022 走看看