---
title: "python小脚本之 IE调用"
author: "shrek"
date: "2009-02-18T14:30:08Z"
tags: []
slug: "python-ie"
draft: false
lastmod: "2009-03-16T17:20:10Z"
id: 334843
url: "https://shrek.iteye.com/blog/334843"
---

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

```java

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(); 这样来调用.