| 1 |
// Package main ... |
| 2 |
package main |
| 3 |
|
| 4 |
import ( |
| 5 |
"fmt" |
| 6 |
"log" |
| 7 |
"net" |
| 8 |
"net/http" |
| 9 |
|
| 10 |
"github.com/go-rod/rod" |
| 11 |
) |
| 12 |
|
| 13 |
func main() { |
| 14 |
page := rod.New().MustConnect().MustPage(testServer()) |
| 15 |
page.MustEval(makeVisibleScript) |
| 16 |
|
| 17 |
log.Printf("waiting 3s for box to become visible") |
| 18 |
|
| 19 |
page.MustElement("#box1").MustWaitVisible() |
| 20 |
log.Printf(">>>>>>>>>>>>>>>>>>>> BOX1 IS VISIBLE") |
| 21 |
|
| 22 |
page.MustElement("#box2").MustWaitVisible() |
| 23 |
log.Printf(">>>>>>>>>>>>>>>>>>>> BOX2 IS VISIBLE") |
| 24 |
} |
| 25 |
|
| 26 |
const ( |
| 27 |
makeVisibleScript = `() => setTimeout(function() { |
| 28 |
document.querySelector('#box1').style.display = ''; |
| 29 |
}, 3000)` |
| 30 |
) |
| 31 |
|
| 32 |
// testServer is a simple HTTP server that serves a static html page. |
| 33 |
func testServer() string { |
| 34 |
l, _ := net.Listen("tcp4", "127.0.0.1:0") |
| 35 |
go func() { |
| 36 |
_ = http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 37 |
_, _ = fmt.Fprint(w, indexHTML) |
| 38 |
})) |
| 39 |
}() |
| 40 |
return "http://" + l.Addr().String() |
| 41 |
} |
| 42 |
|
| 43 |
const indexHTML = `<!doctype html> |
| 44 |
<html> |
| 45 |
<head> |
| 46 |
<title>example</title> |
| 47 |
</head> |
| 48 |
<body> |
| 49 |
<div id="box1" style="display:none"> |
| 50 |
<div id="box2"> |
| 51 |
<p>box2</p> |
| 52 |
</div> |
| 53 |
</div> |
| 54 |
<div id="box3"> |
| 55 |
<h2>box3</h3> |
| 56 |
<p id="box4"> |
| 57 |
box4 text |
| 58 |
<input id="input1" value="some value"><br><br> |
| 59 |
<textarea id="textarea1" style="width:500px;height:400px">textarea</textarea><br><br> |
| 60 |
<input id="input2" type="submit" value="Next"> |
| 61 |
<select id="select1"> |
| 62 |
<option value="one">1</option> |
| 63 |
<option value="two">2</option> |
| 64 |
<option value="three">3</option> |
| 65 |
<option value="four">4</option> |
| 66 |
</select> |
| 67 |
</p> |
| 68 |
</div> |
| 69 |
</body> |
| 70 |
</html>` |