| 1 |
// Package main ... |
| 2 |
package main |
| 3 |
|
| 4 |
import ( |
| 5 |
"log" |
| 6 |
"time" |
| 7 |
|
| 8 |
"github.com/go-rod/rod" |
| 9 |
) |
| 10 |
|
| 11 |
// This example demonstrates how to use a selector to click on an element. |
| 12 |
func main() { |
| 13 |
page := rod.New(). |
| 14 |
MustConnect(). |
| 15 |
Trace(true). // log useful info about what rod is doing |
| 16 |
Timeout(15 * time.Second). |
| 17 |
MustPage("https://pkg.go.dev/time/") |
| 18 |
|
| 19 |
// wait for footer element is visible (ie, page is loaded) |
| 20 |
page.MustElement(`body > footer`).MustWaitVisible() |
| 21 |
|
| 22 |
// find and click "Expand All" link |
| 23 |
page.MustElement(`#pkg-examples`).MustClick() |
| 24 |
|
| 25 |
// retrieve the value of the textarea |
| 26 |
example := page.MustElement(`#example-After textarea`).MustText() |
| 27 |
|
| 28 |
log.Printf("Go's time.After example:\n%s", example) |
| 29 |
} |