0

I need to automate downloading a csv file from my webserver. I am trying to complete this task with selenium for php. I wrote this script and it runs fine on my local machine, it runs, logs in to my admin panel and downloads the file without any errors. But when I upload it to my webserver (where I want to run it as a cronjob) I get the following error:


PHP Fatal error:  Uncaught Facebook\WebDriver\Exception\Internal\IOException: File is not executable. Make sure the path is correct or use environment variable to specify location of the executable. ("chromedriver") in /crons/booking_scraper/vendor/php-webdriver/webdriver/lib/Exception/Internal/IOException.php:14
Stack trace:
#0 /crons/booking_scraper/vendor/php-webdriver/webdriver/lib/Remote/Service/DriverService.php(138): Facebook\WebDriver\Exception\Internal\IOException::forFileError()
#1 /crons/booking_scraper/vendor/php-webdriver/webdriver/lib/Remote/Service/DriverService.php(50): Facebook\WebDriver\Remote\Service\DriverService->setExecutable()
#2 /crons/booking_scraper/vendor/php-webdriver/webdriver/lib/Chrome/ChromeDriverService.php(35): Facebook\WebDriver\Remote\Service\DriverService->__construct()
#3 /crons/booking_scraper/vendor/php-webdriver/webdriver/lib/Chrome/ChromeDriver.php(27): in /crons/booking_scraper/vendor/php-webdriver/webdriver/lib/Exception/Internal/IOException.php on line 14

the path to the vendor folder is correct. I googled for hours and already tried without result:

  • deleting vendor folder and run: composer update (no change)
  • change from RemoteWebDriver to ChromeDriver (both approaches work fine on my local pc)
  • ported the same script to python with selenium (works great on local pc but cannot run python on the hosting server)
  • ported the script to node.js with puppeteer (runs great on my local machine but gives also a lot of errors on the hosting server)

So, I'm out of ideas and need some help here. Here is my code:

<?php

namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\Chrome\ChromeOptions;

require_once('vendor/autoload.php');

// Chromedriver (if started using --port=9515 as above)
$serverUrl = 'http://localhost:9515';
$urls = ['link-to-the-login-form', 'link-to-the-file-to-be-downloaded'];
$pw = 'my-passw';
$user_name = 'my-username';

$chromeOptions = new ChromeOptions();
$chromeOptions->addArguments(['--headless']);
$chromeOptions->setExperimentalOption(
    'prefs', 
    ['download.default_directory' => "./"]
);

$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $chromeOptions);

// Start the browser with $capabilities
$driver = RemoteWebDriver::create($serverUrl, $capabilities);

// Go to URL
$driver->get($urls[0]);
// $driver->manage()->window()->maximize();

$driver->findElement(WebDriverBy::name("username"))
    ->sendKeys($user_name);

$driver->findElement(WebDriverBy::name("password"))
    ->sendKeys($pw);

$driver->findElement(WebDriverBy::name("login"))
    ->click();

echo 'about to download the bookings.csv for you.'.PHP_EOL;
$driver->get($urls[1]);

echo 'ready!'.PHP_EOL;

// give 6sec to download the file before closing the browser
sleep(6);

// Make sure to always call quit() at the end to terminate the browser session
$driver->quit();
mathiflip
  • 67
  • 1
  • 10
  • You want to automate downloading a script, and then you run something on the server ???? And, how (**HOW**) is the file going to be downloaded? – Luuk May 08 '23 at 17:12

0 Answers0