所以我有一个完美的工作代码,直到我今天正在使用脚本的其他部分,并且有一部分突然停止工作,我的代码是:
$host = 'http://host.com:4444/wd/hub';
$caps= DesiredCapabilities::chrome();
$options = new ChromeOptions();
$options->addArguments(['--headless','--no-sandbox', '--window-size=1000,1000']);
$caps->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = RemoteWebDriver::create($host, $caps, 5000);
$driver->manage()->deleteAllCookies();
echo "[".date("r")."]"."---- LOGIN PROCESS ---- \n";
$driver->get("https://www.example.com/login/");
$driver->wait(10)->until(
WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(
WebDriverBy::name('password')
)
);
$driver->takeScreenshot('image.png');
$driver->findElement(WebDriverBy::name('username'))->click();
该元素是一个文本字段,向其发送键会产生相同的异常,即:
Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownCommandException: POST /session/330d05c02583a90a227cddf8c9db000a/element//click
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'srv1.scoding.com', ip: '209.4*****', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-957.12.2.vz7.96.21', java.version: '1.8.0_232'
Driver info: driver.version: unknown in /path/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:106
Stack trace:
#0 /path/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php(326): Facebook\WebDriver\Exception\WebDriverException::throwException(9, 'POST /session/3...', Array)
#1 /path/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php(547): Facebook\WebDriver\Remote\HttpCommandExecutor->execute(Object(Facebook\WebDriver\Remote\WebDriverCommand))
#2 /path/vendor/facebook/webdriver/lib/Remote/RemoteExecuteMethod.php(40): Facebook\WebDr in /path/vendor/facebook/webdriver/lib/Exception/WebDriverException.php on line 106
然而,如果我只是寻找元素并转储返回,它并没有说明无法找到它:
Facebook\WebDriver\Remote\RemoteWebElement Object
(
[executor:protected] => Facebook\WebDriver\Remote\RemoteExecuteMethod Object
(
[driver:Facebook\WebDriver\Remote\RemoteExecuteMethod:private] => Facebook\WebDriver\Remote\RemoteWebDriver Object
(
[executor:protected] => Facebook\WebDriver\Remote\HttpCommandExecutor Object
(
[url:protected] => http://host.com:4444/wd/hub
[curl:protected] => Resource id #26
)
[capabilities:protected] => Facebook\WebDriver\Remote\DesiredCapabilities Object
(
[capabilities:Facebook\WebDriver\Remote\DesiredCapabilities:private] => Array
(
[acceptInsecureCerts] =>
[browserName] => chrome
[browserVersion] => 78.0.3904.70
[chrome] => Array
(
[chromedriverVersion] => 77.0.3865.90 (58c425ba843df2918d9d4b409331972646c393dd-refs/branch-heads/3865@{#830})
[userDataDir] => /tmp/.org.chromium.Chromium.K53sGg
)
[goog:chromeOptions] => Array
(
[debuggerAddress] => localhost:45159
)
[networkConnectionEnabled] =>
[pageLoadStrategy] => normal
[platformName] => linux
[proxy] => Array
(
)
[setWindowRect] => 1
[strictFileInteractability] =>
[timeouts] => Array
(
[implicit] => 0
[pageLoad] => 300000
[script] => 30000
)
[unhandledPromptBehavior] => dismiss and notify
[webdriver.remote.sessionid] => c2fdfaac32d39a20d3def74b7c15ab5b
)
)
[sessionID:protected] => c2fdfaac32d39a20d3def74b7c15ab5b
[mouse:protected] =>
[keyboard:protected] =>
[touch:protected] =>
[executeMethod:protected] => Facebook\WebDriver\Remote\RemoteExecuteMethod Object
*RECURSION*
)
)
[id:protected] =>
[fileDetector:protected] => Facebook\WebDriver\Remote\UselessFileDetector Object
(
)
)
有人知道我做错了什么吗?它不在 iframe 中,它存在,没有对话框,什么都没有。请注意,在点击错误中,没有元素 ID:POST /session/330d05c02583a90a227cddf8c9db000a/element//click
但就图书馆而言,我没有改变任何东西?