github.com/scalingdata/go-ole@v1.2.0/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.CallMethod(ie, "Navigate", "http://www.google.com") 17 oleutil.PutProperty(ie, "Visible", true) 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 window := oleutil.MustGetProperty(document, "parentWindow").ToIDispatch() 28 // set 'golang' to text box. 29 oleutil.MustCallMethod(window, "eval", "document.getElementsByName('q')[0].value = 'golang'") 30 // click btnG. 31 btnG := oleutil.MustCallMethod(window, "eval", "document.getElementsByName('btnG')[0]").ToIDispatch() 32 oleutil.MustCallMethod(btnG, "click") 33 }