D
D
Daria Motorina2020-03-17 23:45:21
symfony
Daria Motorina, 2020-03-17 23:45:21

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']
        );
    }


The option ['download.default_directory' => '/path/to/dir']doesn't work either.
The path to the folder is working, the rights are 775. I can’t pick up other options in order to fundamentally check their performance. What are the possible solutions? Throw out panther and write on bare webdriver?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-03-18
@glaphire

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 question

Ask a Question

731 491 924 answers to any question