如何找到用Chrome的Selenium web驱动程序在PHP中下载的文件的路径和名称


How do I find the path and name of a file downloaded in PHP with Selenium web driver for Chrome?

使用Selenium和Chrome驱动程序下载文件后,如何获取文件名?

该网站回避了这个问题,但给出了简单案例的示例:http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/

我的链接是一个JavaScript链接,它会弹出一个新窗口并自动下载文件,文件名是在服务器上动态生成的。

本网站建议更改下载位置,但对于Firefox:http://elementalselenium.com/tips/2-download-a-file

这列出了所有命令行选项,但没有用于设置下载筛选器的选项:http://www.ericdlarson.com/misc/chrome_command_line_flags.html

这个问题建议您可以更改目录,但答案是Java,它不适用于PHP:Chrome Web驱动程序下载文件

我尝试了以下操作,但出现了错误:

  $options = new ChromeOptions();
  $options->setExperimentalOption('download.default_directory', '''temp');
  $capabilities = DesiredCapabilities::chrome(); // htmlUnitJS()
  $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
  $driver = RemoteWebDriver::create($host, $capabilities, 5000);

PHP致命错误:未捕获异常"UnknownServerException",消息为"未知错误:无法解析功能:chromeOptions"来自未知错误:无法识别的chrome选项:download.default_directory

可能相关:https://groups.google.com/forum/#!topic/macenterprise/cmSKIyzjQA8https://github.com/facebook/php-webdriver/wiki/ChromeOptions

我把它改成了这个,它成功了。它不喜欢'temp路径,并且想要一个关联数组。

  $options = new ChromeOptions();
  $prefs = array('download.default_directory' => 'c:/temp/');
  $options->setExperimentalOption('prefs', $prefs);
  $capabilities = DesiredCapabilities::chrome(); // htmlUnitJS()
  $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
  $driver = RemoteWebDriver::create($host, $capabilities, 5000);