前面控制ie都是新建一個ie。而昨天看了python cookbook,使用python也可以確定已存在的ie窗口。
比如我已經(jīng)有個窗口,URL為http://blog.renren.com/blog/0/addBlog。
然后為了確定這個ie,我們這樣使用:
# -*- coding:utf-8 -*-
from win32com.client import Dispatch
ShellWindowsCLSID = '{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
ShellWindows = Dispatch(ShellWindowsCLSID)
print '%d instances of IE' % len(ShellWindows)
print
for shellwindow in ShellWindows :
print shellwindow.LocationName
print shellwindow.LocationURL
print
if shellwindow.LocationURL=="http://blog.renren.com/blog/0/addBlog":
print "Find"
break
ie=shellwindow
doc=ie.Document
body=doc.body
for i in body.getElementsByTagName("input"):
if str(i.getAttribute("id"))=="title":
print "Find title"
i.value="AutoCreatedByPython"
break
其實這個我也不太懂,只知道 ShellWindowsCLSID 其實在注冊表中對應(yīng)的。這個找到的是全部的ie窗口。
閱讀全文
類別:默認分類 查看評論文章來源:
http://hi.baidu.com/mirguest/blog/item/c134bef2f78afdbca40f52a1.html