Skip to content

Instantly share code, notes, and snippets.

@mmaz
Last active February 28, 2016 23:14
Show Gist options
  • Save mmaz/5930805 to your computer and use it in GitHub Desktop.
Save mmaz/5930805 to your computer and use it in GitHub Desktop.
Selenium Scala REPL
name := "SeleniumPlayground"
scalaVersion := "2.10.3"
libraryDependencies += "org.seleniumhq.selenium" % "selenium-chrome-driver" % "2.39.0"

Selenium Scala REPL

Why Scala?

A REPL is helpful for quick script development with selenium. Scala's REPL offers built-in tab completion and persistent history across sessions. Selenium's javadocs are also more user-friendly than their python counterparts.

Try it out

In a new directory, create a build.sbt file with, at minimum, a project name of your choice and a [dependency on selenium] 1. Now, you can launch the scala console from within sbt. If you're using chromedriver, download the driver into the directory or [add a property] 2 with the correct path prior to instantiating ChromeDriver.

$ sbt update
$ sbt
sbt > console
scala >  import org.openqa.selenium.chrome.ChromeDriver
scala > val chrome = new ChromeDriver()
scala > chrome.get("http://www.nytimes.com")
scala > chrome.quit  
scala > exit
sbt > exit
@divyesh86
Copy link

Got an error -- java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

Is there a way to work with chrome driver without setting the system property ?

@nex0ma
Copy link

nex0ma commented Feb 28, 2016

$ sbt run

with:

object Se {
    def main(args: Array[String]){
        System.setProperty("webdriver.chrome.driver", "./chromedriver");
        import org.openqa.selenium.chrome.ChromeDriver
        val chrome = new ChromeDriver()
        chrome.get("http://localhost")
        chrome.quit
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment