forked from chrome-php/chrome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform-submit.php
More file actions
29 lines (21 loc) · 749 Bytes
/
form-submit.php
File metadata and controls
29 lines (21 loc) · 749 Bytes
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
<?php
require __DIR__ . '/../vendor/autoload.php';
use HeadlessChromium\BrowserFactory;
// open browser
$factory = new BrowserFactory();
$browser = $factory->createBrowser();
// navigate to a page with a form
$page = $browser->createPage();
$page->navigate('file://' . __DIR__ . '/html/form.html')->waitForNavigation();
// put 'hello' in the input and submit the form
$evaluation = $page->evaluate(
'(() => {
document.querySelector("#myinput").value = "hello";
document.querySelector("#myform").submit();
})()'
);
// wait for the page to be reloaded
$evaluation->waitForPageReload();
// get value in the new page
$value = $page->evaluate('document.querySelector("#value").innerHTML')->getReturnValue();
var_dump($value);