ITeye博客

python小脚本之 IE调用

shrek · 2009-02-18 14:30 · python · Markdown

项目进行到测试阶段,总是要不厌其烦的打开IE来登录项目, 每天也大概有个N次。。 写个python 小脚本以减少一点工作量


import win32com.client
import time
ie6=win32com.client.Dispatch("InternetExplorer.Application")
ie6.Navigate("http://localhost/skyenet/")
ie6.Visible=1
while ie6.Busy:
  time.sleep(1)

document=ie6.Document
document.getElementById("username").value="alibaba"
document.getElementById("password").value="zhimakamen"
document.forms[0].submit()


以上ip,用户密码,纯属虚构..

以上document就是页面打开后面DOM对象,因为页面里的javascript方法是在window命名空间,所以如果要调用js, 可以用 document.parentWindow.doSomeThing(); 这样来调用.

评论(2)

  1. #2 楼 · shrek · 2009-03-01 10:34

    rainman.jin writes:

    Python3.0的windows扩展还没有出来吧?

    已经出来了,2月16的build 213有for py3.0的

  2. #1 楼 · rainman.jin · 2009-03-01 06:21

    Python3.0的windows扩展还没有出来吧?

评论功能维护中,当前仅展示历史评论。