forked from go-ole/go-ole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ie.go
33 lines (27 loc) · 901 Bytes
/
ie.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// +build windows
package main
import (
"time"
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("InternetExplorer.Application")
ie, _ := unknown.QueryInterface(ole.IID_IDispatch)
oleutil.CallMethod(ie, "Navigate", "http://www.google.com")
oleutil.PutProperty(ie, "Visible", true)
for {
if oleutil.MustGetProperty(ie, "Busy").Val == 0 {
break
}
}
time.Sleep(1e9)
document := oleutil.MustGetProperty(ie, "document").ToIDispatch()
window := oleutil.MustGetProperty(document, "parentWindow").ToIDispatch()
// set 'golang' to text box.
oleutil.MustCallMethod(window, "eval", "document.getElementsByName('q')[0].value = 'golang'")
// click btnG.
btnG := oleutil.MustCallMethod(window, "eval", "document.getElementsByName('btnG')[0]").ToIDispatch()
oleutil.MustCallMethod(btnG, "click")
}