python3实战–selenium自动化输入手机、selenium自动化百度搜索、拖拽阿里云滑动验证、模拟鼠标双击、模拟鼠标拖拽
参考:https://www.cnblogs.com/win0211/p/12107003.html
https://blog.csdn.net/qq_33371343/article/details/78916751
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 15:10:58 2020
@author: fern.xu
"""
import datetime
import win32api
import win32gui
import win32con
import ctypes
import time
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
def open_browser():
'''
browser = webdriver.Chrome()
#browser.get('https://m-fat.wldxxx.net/gsd/index.html?channel=op_prm_dxt_00140107')
#browser.get('https://m-fat.wldxxx.net/gsd/index.html')
#browser.get('https://promotion.aliyun.com/ntms/act/captchaIntroAndDemo.html?spm=5176.10695662.1386720.1.5b12fbadh3Ot0G&wh_ttid=pc')
browser.get('http://172.27.110.239/download/1.html')
#browser.find_element_by_name("mobile").send_keys("13333333333")#自动输入手机号码
#browser.find_element_by_name("opt").click()
browser.maximize_window()
drag1 = browser.find_element_by_id('dragEle')#获取第一,二,三能拖拽的元素
action_chains = ActionChains(browser)# 创建一个新的ActionChains,将webdriver实例对driver作为参数值传入,然后通过WenDriver实例执行用户动作
#将页面上的第一个能被拖拽的元素拖拽到第二个元素位置
#将页面上的第三个能拖拽的元素,向右下拖动10个像素,共拖动5次
action_chains.drag_and_drop_by_offset(drag1, 208, 0).perform()
time.sleep(5)#休眠3秒
browser.quit()
'''
browser = webdriver.Chrome()
browser.get('https://promotion.aliyun.com/ntms/act/captchaIntroAndDemo.html?spm=5176.10695662.1386720.1.5b12fbadh3Ot0G&wh_ttid=pc')
drag1 = browser.find_element_by_id('nc_1_n1z')#获取第一,二,三能拖拽的元素
action_chains = ActionChains(browser)
action_chains.drag_and_drop_by_offset(drag1, 258, 0).perform()
time.sleep(5)
browser.quit()
'''
browser.get('https://www.baidu.com')#打开百度网页
browser.find_element_by_id("kw").send_keys("selenium")# 输入需要查询的关键字
browser.find_element_by_id("su").click()#点击“百度一下”进行搜索
'''
open_browser()#打开浏览器输入手机号码
'''
def mouse_click(x,y): #鼠标双击动作
ctypes.windll.user32.SetCursorPos(x,y)
ctypes.windll.user32.mouse_event(2,0,0,0,0)
ctypes.windll.user32.mouse_event(4,0,0,0,0)
#重复上面两条语句属于双击
#ctypes.windll.user32.mouse_event(2,0,0,0,0)
#ctypes.windll.user32.mouse_event(4,0,0,0,0)
def mouse_doSth():
print('获取短信验证码')
mouse_click(936,635)#我的电脑的鼠标坐标位置
time.sleep(3)
mouse_doSth()#触发短信验证码
def mouse_move():#鼠标按下不放,从一个坐标点直线拖动到另外一个坐标点
ctypes.windll.user32.SetCursorPos(102, 327)#鼠标按下的坐标点
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 102, 327, 102, 327)
time.sleep(2)z
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE + win32con.MOUSEEVENTF_MOVE, 102, 327, 360, 327)
time.sleep(2)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 360, 327, 360, 327)
ctypes.windll.user32.SetCursorPos(360, 327)#鼠标停在最后弹起的坐标点
mouse_move()
'''