github.com/go-ole/go-ole@v1.2.6/_example/ie/ie.go (about) 1 // +build windows 2 3 package main 4 5 import ( 6 "time" 7 8 ole "github.com/go-ole/go-ole" 9 "github.com/go-ole/go-ole/oleutil" 10 ) 11 12 func main() { 13 ole.CoInitialize(0) 14 unknown, _ := oleutil.CreateObject("InternetExplorer.Application") 15 ie, _ := unknown.QueryInterface(ole.IID_IDispatch) 16 oleutil.PutProperty(ie, "Visible", true) 17 oleutil.CallMethod(ie, "Navigate", "http://www.google.com") 18 for { 19 if oleutil.MustGetProperty(ie, "Busy").Val == 0 { 20 break 21 } 22 } 23 24 time.Sleep(1e9) 25 26 document := oleutil.MustGetProperty(ie, "document").ToIDispatch() 27 28 // set 'golang' to text box. 29 elems := oleutil.MustCallMethod(document, "getElementsByName", "q").ToIDispatch() 30 q := oleutil.MustCallMethod(elems, "item", 0).ToIDispatch() 31 oleutil.MustPutProperty(q, "value", "golang") 32 33 // click btnK. 34 elems = oleutil.MustCallMethod(document, "getElementsByName", "btnK").ToIDispatch() 35 btnG := oleutil.MustCallMethod(elems, "item", 0).ToIDispatch() 36 oleutil.MustCallMethod(btnG, "click") 37 }