Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll down browser page - Laravel Dusk (Browser Tests)

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)
                ;
        });
    }
}
like image 754
Tomasz Avatar asked Mar 22 '17 12:03

Tomasz


2 Answers

You can use now the script method:

$browser->script('window.scrollTo(0, 500);');

like image 143
BrianEDT Avatar answered Sep 18 '22 12:09

BrianEDT


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;
    });
}
like image 22
Christophvh Avatar answered Sep 21 '22 12:09

Christophvh