Skip to content

Instantly share code, notes, and snippets.

@gomo
Last active August 29, 2015 13:56
Show Gist options
  • Save gomo/9130020 to your computer and use it in GitHub Desktop.
Save gomo/9130020 to your computer and use it in GitHub Desktop.
seleniumをphantomjsで動かす

seleniumを起動

java -jar /path/to/selenium-server-standalone-2.39.0.jar -role hub

phantomjsを起動

phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444

javaのコード

//ドライバ生成
DesiredCapabilities capability = DesiredCapabilities.phantomjs();
WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:8080"), capability);

//ページを開く
driver.get("http://www.google.com");

//スクリーンショットを取る
File scrFile = ((TakesScreenshot)new Augmenter().augment(driver)).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("screenshot.png"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment