ChromeDriver Laravel Dusk Set下载文件路径 [英] ChromeDriver Laravel Dusk Set Download File Path
本文介绍了ChromeDriver Laravel Dusk Set下载文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我想问一下如何将chromeDriver选项的默认路径设置为特定目录,以便如果使用laravel dusk无头驱动程序下载文件,则文件会下载到该目录.
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.
谢谢.
推荐答案
尝试一下:
$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('/');
});
将/your/download/path
替换为实际路径.
此示例需要 guzzlehttp/guzzle
包来执行POST请求.
This example requires the guzzlehttp/guzzle
package to execute the POST request.
还有其他不受外部依赖的解决方案:
如何使用PHP发送POST请求?
There are other solutions without external dependencies:
How do I send a POST request with PHP?
这篇关于ChromeDriver Laravel Dusk Set下载文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文