laravel-dusklaravel-dusk2

Simulate key with Laravel Dusk (without input element)


I have a page which consists of some disabled inputs, spans and divs.
In the background I wait for pressed keys. Background of this is some memory game.
My problem is, that it turned out to be pretty hard to test.
I know two functions to simulate input: type() and keys(). When I use keys("@someElement", "34"), I get "element not interactable". Similar happens with type() (well that's not surprising as type suggests filling some input).

How can I properly simulate a pressed key without using an active input element?


Solution

  • Use the underlying driver:

    $browser->driver->getKeyboard()->sendKeys('a');
    $browser->driver->getKeyboard()->sendKeys(\Facebook\WebDriver\WebDriverKeys::ENTER);