Skip to content

Instantly share code, notes, and snippets.

@ekos
Created April 24, 2017 15:35
Show Gist options
  • Save ekos/dc8ef6388540fd7c026a197b0ea52572 to your computer and use it in GitHub Desktop.
Save ekos/dc8ef6388540fd7c026a197b0ea52572 to your computer and use it in GitHub Desktop.
<?php
require_once dirname(__FILE__) . "/phpwebdriver/WebDriver.php";
require_once dirname(__FILE__) . "/phpwebdriver/LocatorStrategy.php";
$URL = "http://example.com/";
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
//サイトアクセス
$webdriver->get($URL);
//More information...をクリック
$informationElement = $webdriver->findElementBy(LocatorStrategy::xpath, "/html/body/div/p[2]/a");
$informationElement->click();
sleep(2);//アクセスに時間がかかるので、待機する
//スクリーンショットの取得
file_put_contents('example.png', $webdriver->getScreenshot());
//ページソースの取得
file_put_contents('example.html', $webdriver->getPageSource());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment