Answer the question
In order to leave comments, you need to log in
How to set download folder in symfony/panther?
I am writing a script to automate downloading files through a browser. I use symfony/panther in browser emulation mode. It has php Webdriver under the hood . There is a discussion in panther issues about adding chrome options control, but at the same time, according to the documentation, it is said that you can add options in the client constructor arguments ( github link ).
Now I have this simplified code:
<?php
namespace App\Module\SymfonycastsParser\Services;
use Symfony\Component\Panther\Client;
class ParserService
{
private $browserClient;
public function __construct()
{
$this->browserClient = Client::createChromeClient(
null,
['--window-size=1200,1100'],
['download.default_directory=/path/to/dir']
);
}
['download.default_directory' => '/path/to/dir']
doesn't work either. Answer the question
In order to leave comments, you need to log in
I found the answer to my question :)
1. Panther is good, but chrome fine-tuning is not implemented there now. Rewrote to php-webdriver .
2. There are very meager examples on the wiki on how to add settings to chrome, almost all parameters are configured through setExperimentalOptions(), even if these are profile settings.
3. I found the correct answer using stackoverflow: link
Simplified code looks like this:
<?php
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
class ParserService
{
private $webdriver;
public function __construct()
{
$host = 'http://localhost:4444';
$options = new ChromeOptions();
$options->setExperimentalOption("prefs", [
"download.prompt_for_download" => false,
"download.directory_upgrade" => true,
"safebrowsing.enabled" => true,
"download.default_directory" => "/path/to/dir",
]);
$caps = DesiredCapabilities::chrome();
$caps->setCapability(ChromeOptions::CAPABILITY, $options);
$this->webdriver = RemoteWebDriver::create($host, $caps);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question