LoginSignup
14
14

More than 5 years have passed since last update.

Scala で PhantomJS を使う

Last updated at Posted at 2014-08-12

Selenium と PhantomJS ドライバーを入れるだけ。

build.sbt
name := "HogeHoge"

version := "0.1"

scalaVersion := "2.10.3"

libraryDependencies += ("com.github.detro.ghostdriver" % "phantomjsdriver" % "1.1.0").
                        exclude("org.seleniumhq.selenium", "jetty-repacked")

あとは FirefoxDriver と同じように扱える。

main.scala
def main(args: Array[String]) {
    implicit val driver = new PhantomJSDriver()

    driver.get("http://google.com")
    val file = driver.getScreenshotAs(OutputType.FILE)
    Files.copy(Paths.get(file.toURI), Paths.get(file.getName))

    driver.quit()
}

結果

screenshot1875077328556248451.png

ちょうかんたん!

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