LoginSignup
4
1

More than 3 years have passed since last update.

facebook/php-webdriver 1.6 で「Undefined index: ELEMENT」

Last updated at Posted at 2019-06-07

docker-selenium、php-webdriverを用いて、seleniumのfindElement、sendKeysを実行するとNoticeエラー「Undefined index: ELEMENT」が発生、その解決方法を記載します。

現象発生内容

環境

  • selenium/node-chrome-debug 3.141.59-palladium
  • selenium/hub 3.141.59-palladium
  • facebook/php-webdriver 1.6

原因

https://github.com/SeleniumHQ/docker-selenium/issues/916 によると
Chrome 75ではデフォルトでW3Cモードになり、上記環境ではそのW3Cモードになります。
また、facebook/php-webdriver のREADMEに

This library is compatible with Selenium server version 2.x and 3.x. It implements the JsonWireProtocol, which is currently supported by the Selenium server and will also implement the W3C WebDriver specification in the future.

とあり、現状でW3Cに対応していないために現象が発生します。

解決方法

下記の通り、Chrome 75未満の環境にする。

  • selenium/node-chrome-debug 3.141.59-mercury
  • selenium/hub 3.141.59-mercury
  • facebook/php-webdriver 1.6

参考:node-chrome-debugイメージ一覧

余談

W3Cの場合、findElementまたはfindElementsを実行した場合のjsonレスポンスが下記になります。

findElement
{
  "state": "success",
  "sessionId": null,
  "class": "org.openqa.selenium.remote.Response",
  "value": {
    "element-6066-11e4-a52e-4f735466cecf": "2f61f66d-3d44-400b-a986-410693b88e0c"
  },
  "status": 0
}
findElements
{
  "state": "success",
  "sessionId": null,
  "class": "org.openqa.selenium.remote.Response",
  "value": [
    {
      "element-6066-11e4-a52e-4f735466cecf": "a0c08d8f-1592-43b8-9cc4-3be8287e8d71"
    }
  ],
  "status": 0
}

W3Cでない場合は、この "element-6066-11e4-a52e-4f735466cecf" 部分が "ELEMENT" となるようです。

facebook/php-webdriver 1.6 では "ELEMENT" がある前提になっているので、RemoteWebDriver.php において、

RemoteWebDriver.php
// return $this->newElement($raw_element['ELEMENT']);
return $this->newElement(current($raw_element));

のように修正すれば上手く動作すると思います。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1