-
Notifications
You must be signed in to change notification settings - Fork 240
/
main.go
40 lines (35 loc) · 970 Bytes
/
main.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
34
35
36
37
38
39
40
// Command click is a chromedp example demonstrating how to use a selector to
// click on an element.
package main
import (
"context"
"log"
"time"
"github.com/chromedp/chromedp"
)
func main() {
// create chrome instance
ctx, cancel := chromedp.NewContext(
context.Background(),
// chromedp.WithDebugf(log.Printf),
)
defer cancel()
// create a timeout
ctx, cancel = context.WithTimeout(ctx, 15*time.Second)
defer cancel()
// navigate to a page, wait for an element, click
var example string
err := chromedp.Run(ctx,
chromedp.Navigate(`https://pkg.go.dev/time`),
// wait for footer element is visible (ie, page is loaded)
chromedp.WaitVisible(`body > footer`),
// find and click "Example" link
chromedp.Click(`#example-After`, chromedp.NodeVisible),
// retrieve the text of the textarea
chromedp.Value(`#example-After textarea`, &example),
)
if err != nil {
log.Fatal(err)
}
log.Printf("Go's time.After example:\n%s", example)
}