I'm preparing tests using [Browser Tests (Laravel Dusk)][1]
[1]: https://laravel.com/docs/5.4/dusk and I need force click to element which is not see before scroll down browser page. How can define in dusk test to click unsee element or scroll browser page ?
class SliderTest extends DuskTestCase
{
/**
* A Dusk test example.
*
* @return void
*/
public function testExample()
{
$this->browse(function ($browser) {
$browser
->visit('http://localhost:8000/admin/login')
->click('label[for=test_1]')
->pause(500)
;
});
}
}
You can use now the script
method:
$browser->script('window.scrollTo(0, 500);');
Based on the answer from @james
you can execute scripts, but these cannot be chained. So you can just execute the scroll before the click occurs.
public function testExample()
{
$this->browse(function ($browser) {
$browser
->visit('http://localhost:8000/admin/login')
->driver->executeScript('window.scrollTo(0, 500);');
// can't chain methods after this
$browser
->click('label[for=test_1]')
->pause(500) //you can keep chaining here;
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With