LoginSignup
2
2

More than 5 years have passed since last update.

Windows7でSeleniumを使う

Last updated at Posted at 2018-04-23

Windows7

PHP7.2.4

公式サイトから64bitスレッドセーフ版をダウンロード(php-7.2.4-Win32-VC15-x64.zip)。C:\PHPに配置。

Visual C++2017

PHPを動かすために必要らしい。マイクロソフトからダウンロード。

Composer

公式サイトからダウンロード。インストーラ実行。コマンドプロンプトでcomposerと打ってロゴが出ればok。

ChromeDriver

公式サイトからダウンロード。

PHP.ini

extension=curlの先頭のセミコロンを外して上書き。

Selenium(facebook/webdriver)

何かディレクトリを作ってそこに移動。
コマンドプロンプトでcomposer require facebook/webdriberと打ってインストール。

実行するスクリプトは下記を参照
https://qiita.com/tsuuuuu_san/items/61379b797878d0e0f4d7

環境構築に躊躇していましたが、意外とすんなり入りました。

さてFirefoxも試そうとしたところ、ハマりました。

Seleniumのバージョンを3.4

Firefoxのバージョンを60.0

あらかじめStandaloneを起動してからPHPを実行
java -jar selenium-server-standalone-3.4.0.jar -port 4445

失敗

Firefox起動のたびにSSLが自己証明書になっているとの警告

以下のコードで解決

$profile = new FirefoxProfile();
$caps = DesiredCapabilities::firefox();
$caps->setCapability(FirefoxDriver::PROFILE, $profile);
$caps->setCapability('marionette', true);
$caps->setCapability('testCap', true);
$caps->setCapability('acceptInsecureCerts', true);

// selenium
$host = 'http://localhost:4445/wd/hub';
// chrome ドライバーの起動
$this->driver = RemoteWebDriver::create($host,$caps);

could not be scrolled into view

情報がない。困った。

依然として原因が不明だが、以下のコードを入れたところ、とりあえずうまくいく。

$dimension = new WebDriverDimension(800, 600);
$this->driver->manage()->window()->setSize($dimension);
2
2
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
2
2