LoginSignup
0
0

More than 1 year has passed since last update.

php-webdriverでエラーが発生し、要素の取得ができない

Posted at

現象

echo $driver->findElements(WebDriverBy::tagName("a"))[1]->getText();

など、要素を取得しようとすると、

Fatal error: Uncaught Facebook\WebDriver\Exception\UnknownCommandException: GET /session/d6ad6784c4b4c042ffaefe2def5a305f/element//text

を表示。(sessionの後の値は都度変わる)

//Googleのホームページに移動
$url = 'https://www.google.com/';
$driver->get($url);

//終了
$driver->quit();

など、起動や終了は問題なくできます。

原因

php-webdriverのバージョンが古いことが問題でした。

バージョンを指定せずにインストールしていたので、最新版が入っているとばかり思っていましたが、バージョンを確認すると、1.3.0でした。(1.3.0は2017年リリース。2021年6月9日現在の最新版は1.11.1)

↑ ここから確認すると、1.4.0からはext-zipが必要になっており、使用しているmacのPHPのバージョンではext-zipが使用できなかったため、1.3.0になってしまったようです。

対応

PHPのバージョンを上げて、php-webdriverの最新版をインストールしたら、無事動作するようになりました!

0
0
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
0
0