如何在PHP中上传Selenium中的文件?应只有1个文件.有:0


How do I upload a file in Selenium in PHP? Expected there to be only 1 file. There were: 0

根据我正在使用的库的文档,这应该可以工作,但事实并非如此。https://github.com/facebook/php-webdriver/wiki/Upload-a-file

这是错误

Finding ctl00_WorkSpaceContent_sourceFile
PHP Fatal error:  Uncaught exception 'UnknownServerException' with message 'Expected there to be only 1 file. There were: 0

这是代码

echo "Finding ctl00_WorkSpaceContent_sourceFile'n";
$input = $driver->findElement(WebDriverBy::id("ctl00_WorkSpaceContent_sourceFile"));
// set the file detector
$input->setFileDetector(new LocalFileDetector());
// upload the file and submit the form
$input->sendKeys($file);
echo "Finding Save & Return'n";

这是HTML

<input name="ctl00$WorkSpaceContent$sourceFile" type="file" id="ctl00_WorkSpaceContent_sourceFile" class="formrequired" size="62" onchange="javascript:this.className='formchanged';">

网络上没有错误的结果,甚至谷歌也没有。DuckDuckGo,谷歌

我看到了一些相关的问题,但它们是关于发送文件以删除Selenium服务器的。我的是本地的。

尽管库发出警告,我还是不得不将文件名作为数组发送。

$input->sendKeys(array($file));

PHP警告:is_file()要求参数1为有效路径,数组在第23行的/cygdrive/c/Users/Chloe/workspace/Tiads/PHP-webdriver/lib/remote/LocalFileDetector.PHP中给定

我将更新Wiki链接。