| 376 | } |
| 377 | |
| 378 | func Example_retrieveHTML() { |
| 379 | ctx, cancel := chromedp.NewContext(context.Background()) |
| 380 | defer cancel() |
| 381 | |
| 382 | ts := httptest.NewServer(writeHTML(` |
| 383 | <body> |
| 384 | <p id="content" onclick="changeText()">Original content.</p> |
| 385 | <script> |
| 386 | function changeText() { |
| 387 | document.getElementById("content").textContent = "New content!" |
| 388 | } |
| 389 | </script> |
| 390 | </body> |
| 391 | `)) |
| 392 | defer ts.Close() |
| 393 | |
| 394 | if err := chromedp.Do(ctx, chromedp.Navigate(ts.URL)); err != nil { |
| 395 | log.Fatal(err) |
| 396 | } |
| 397 | outerBefore, err := chromedp.Run(ctx, chromedp.OuterHTML(chromedp.CSS("#content"))) |
| 398 | if err != nil { |
| 399 | log.Fatal(err) |
| 400 | } |
| 401 | if err := chromedp.Do(ctx, chromedp.Click(chromedp.CSS("#content"))); err != nil { |
| 402 | log.Fatal(err) |
| 403 | } |
| 404 | outerAfter, err := chromedp.Run(ctx, chromedp.OuterHTML(chromedp.CSS("#content"))) |
| 405 | if err != nil { |
| 406 | log.Fatal(err) |
| 407 | } |
| 408 | fmt.Println("OuterHTML before clicking:") |
| 409 | fmt.Println(outerBefore) |
| 410 | fmt.Println("OuterHTML after clicking:") |
| 411 | fmt.Println(outerAfter) |
| 412 | |
| 413 | // Output: |
| 414 | // OuterHTML before clicking: |
| 415 | // <p id="content" onclick="changeText()">Original content.</p> |
| 416 | // OuterHTML after clicking: |
| 417 | // <p id="content" onclick="changeText()">New content!</p> |
| 418 | } |
| 419 | |
| 420 | func ExampleEmulate() { |
| 421 | ctx, cancel := chromedp.NewContext(context.Background()) |