selenium 自动化中断浏览器加载,加快自动化与运行速度

Python模拟点击参考:http://blog.csdn.net/madrabbit1987/article/details/77869928


脚本思路:浏览器页面跳转,浏览器进行加载导致页面无法定位,此时通过Python pymouse 模块 模拟鼠标点击当前页签空白区域,然后通过Python win32api键按下ESC中断浏览器加载,然后就可以开始我们的定位了,从而加快自动化执行速度!

#coding=utf-8
from selenium import webdriver
import time,random,os,win32api,win32con
from public import *
from pymouse import PyMouse

def stopLoading():
    win32api.keybd_event(27,0,0,0)
    win32api.keybd_event(27,0,win32con.KEYEVENTF_KEYUP,0)
    return

startTime = int(time.time())
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.jd.com/')
driver.implicitly_wait(10)
driver.find_element_by_link_text('手机通讯').click()
time.sleep(1)
mouse = PyMouse()
mouse.click(100,600)  #移动并且在(x,y)位置点击
stopLoading()
driver.find_element_by_link_text('我的购物车').click()
time.sleep(2)
driver.quit()
endTime = int(time.time())
differenceTime = endTime - startTime         
print differenceTime


猜你喜欢

转载自blog.csdn.net/qq_35741999/article/details/79434522
今日推荐