ChromeDriver Laravel Dusk Set Download File Path

蓝咒 提交于 2019-12-11 18:08:30

问题


Hi all wanted to ask how to set chromeDriver options default path to a specific directory so that if one downloads file using laravel dusk headless driver, files downloads to the directory.

Thanks in advance.


回答1:


Try this:

$this->browse(function (Browser $browser) {
    $url = $browser->driver->getCommandExecutor()->getAddressOfRemoteServer();
    $uri = '/session/' . $browser->driver->getSessionID() . '/chromium/send_command';
    $body = [
        'cmd' => 'Page.setDownloadBehavior',
        'params' => ['behavior' => 'allow', 'downloadPath' => '/your/download/path']
    ];
    (new \GuzzleHttp\Client())->post($url . $uri, ['body' => json_encode($body)]);

    $browser->visit('/');
});

Replace /your/download/path with the actual path.

This example requires the guzzlehttp/guzzle package to execute the POST request.

There are other solutions without external dependencies:
How do I send a POST request with PHP?



来源:https://stackoverflow.com/questions/48888036/chromedriver-laravel-dusk-set-download-file-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!