"""
PAMIE Build 3.0a
Based on cPAMIE and PAM.py by RLM
Revised: March 03, 2009
Developers: Robert L. Marchetti
Description: This python class file allow you to write scripts to Automate the Internet Explorer Browser Client.
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Special Thanks to: All the Pamie Users and Developers for their time and effort, Steve M., Drunk Bum, Jeff H.,
Dave K., Henry W., Tom C., Scott W.,Margie M. and all others for there support and contributions.
See !whatsnew.txt for modification history.
"""
import sys
sys.path.append(r'c:\python24\lib')
import win32com.client
import win32gui
import pywintypes
import time
import win32con
import pdb
import re
import random
import string
import pythoncom
import datetime,os,sys
import traceback
class PAMIE:
"""
cPAMIE is an automation object based on the work of PAMIE by RLM
http://pamie.sourceforge.net/
"""
__version__ = "3.0"
def __init__(self, url=None, timeOut=3000):
""" The class instantiation code. When the object is instantiated you can
pass a starting URL. If no URL is passed then about:blank, a blank
page, is brought up.
parameters:
[url] - url to navigate to initially
[timeOut] - how many 100mS increments to wait, 10 = 1sec, 100=10sec
returns:
Nothing
"""
#pythoncom.CoInitialize()
self.showDebugging = True # Show debug print lines?
self.colorHighlight = "#F6F7AD" # Set to None to turn off highlighting
self.frameName = None # The current frame name or index. Nested frames are
# supported in the format frame1.frame2.frame3
self.formName = None # The current form name or index
self.busyTuner = 1 # Number of consecutive checks to verify document is no longer busy.
self._ie = win32com.client.dynamic.Dispatch('InternetExplorer.Application')
if url:
self._ie.Navigate(url)
else:
self._ie.Navigate('about:blank')
self._timeOut = timeOut
self._ie.Visible = 1
#self._ie.resizable = 1
#self._ie.fullscreen = 1
self._ie.MenuBar=1
self._ie.ToolBar=1
self._ie.AddressBar=1
self.timer = datetime.datetime.now()
def _docGetReadyState(self, doc):
""" Gets the readyState of a document. This is a seperate function so
the "Access Denied" error that IE throws up every once in a while can
be caught and ignored, without breaking the timing in the wait() functions.
parameters:
doc - The document
returns:
The readyState.
"""
try:
return doc.readyState
except:
return ""
def _frameWait(self, frame=None):
""" Waits for a page to be fully loaded. A completely soundproof method has yet to be found to accomplish
this, but the function works in the majority of instances. The function waits for both the doc busy attribute
to be False and the doc readyState to be 'complete'. It will continue to wait until the maximim timeOut
value has been reached. In addition, the busyTuner can be adjusted to force the function to verify the
specified number of consecutive 'not busy and completed' checks before continuing.
parameters:
[frame] - A frame element.
returns:
True if the wait was successful, else False
"""
readyCount = 0
timeLeft = self._timeOut
try:
if frame:
myFrame = frame
else:
myFrame = self.getFrame(self.frameName)
while readyCount < self.busyTuner and timeLeft > 0:
try:
doc = myFrame.document
except:
continue # if the document never gets itself together this will timeout
if self._ie.Busy == False and self._docGetReadyState(doc) == 'complete':
readyCount += 1
else:
readyCount = 0
time.sleep(0.05)
timeLeft -= 1
except:
(ErrorType,ErrorValue,ErrorTB)=sys.exc_info()
print (sys.exc_info())
traceback.print_exc(ErrorTB)
return False
else:
return True
def _wait(self):
""" Waits for a page to be fully loaded. A completely soundproof method has yet to be found to accomplish
this, but the function works in the majority of instances. The function waits for both the doc busy attribute
to be False and the doc readyState to be 'complete'. It will continue to wait until the maximim timeOut
value has been reached. In addition, the busyTuner can be adjusted to force the function to verify the
specified number of consecutive 'not busy and completed' checks before continuing.
parameters:
None
returns:
True if the wait was successful, else False
"""
readyCount = 0
timeLeft = self._timeOut
try:
while readyCount < self.busyTuner and timeLeft > 0:
try:
doc = self._ie.Document
except:
continue # if the document never gets itself together this will timeout
if self._ie.Busy == False and self._docGetReadyState(doc) == 'complete':
readyCount += 1
else:
readyCount = 0
time.sleep(0.05)
timeLeft -= 1
except:
(ErrorType,ErrorValue,ErrorTB)=sys.exc_info()
print (sys.exc_info())
traceback.print_exc(ErrorTB)
return False
else:
return True
def buttonExists(self, name):
""" Checks to see if a button exists
parameters:
name - The id, name, value or index of the button.
returns:
True if the button is found, else False
"""
myElement = self.getButton(name)
if myElement:
return True
else:
return False
def changeWindow(self, wintext):
""" changeWindow()
changes control to new or existing window
Parms:
wintext - title of window to control
"""
# Grab the POP-UP Window
newWin = self.windowFind(wintext)
# Use Pamie for COM object for POP-UP Window
self._ie = newWin
return self._ie
def checkBoxExists(self, name):
""" Checks to see if a checkbox exists
parameters:
name - Th
没有合适的资源?快使用搜索试试~ 我知道了~
python pamie pam3.0
共2个文件
py:2个
5星 · 超过95%的资源 需积分: 9 50 下载量 159 浏览量
2011-08-21
22:56:28
上传
评论
收藏 19KB ZIP 举报
温馨提示
pam3.0不用解释。pam3.0不用解释。pam3.0不用解释。pam3.0不用解释。pam3.0不用解释。
资源推荐
资源详情
资源评论
收起资源包目录
PAM3.0.zip (2个子文件)
PAM30.py 83KB
winGuiAuto.py 30KB
共 2 条
- 1
liquid78
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页