I’m working with chrome-php/chrome right now. I have problems when to execute keyboard key press for Enter. Are there any ways to do that ?
I have already trying to execute the code but there are no options. Maybe there are alternatives how to do that ?
below is the code I use to test.
$browserFactory = new BrowserFactory();
// starts headless Chrome
$browser = $browserFactory->createBrowser([
'windowSize' => [1920, 1000],
]);
try {
$page = $browser->createPage();
$page->setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36');
$page->navigate('https://www.google.com/')->waitForNavigation();
try {
$page->mouse()->find('textarea')->click();
$page->keyboard()
->typeText('travel the world');
$page->keyboard()
->typeRawKey('Enter');
} catch (ElementNotFoundException $exception) {
// element not found
}
$pageTitle = $page->evaluate('document.title')->getReturnValue();
$page->screenshot()->saveToFile('bar.png');
} finally {
$browser->close();
}