The webdriver package

[Tags: bsd3, library]


For more information about Selenium itself, see


[Skip to ReadMe]


Dependenciesaeson (>= && <0.11), attoparsec (<0.14), base (==4.*), base64-bytestring (==1.0.*), bytestring (>=0.9 && <0.11), cond (>=0.3 && <0.5), data-default (>=0.2 && <1.0), directory (==1.*), directory-tree (>=0.11 && <0.13), exceptions (>=0.4 && <0.9), filepath (==1.*), http-client (>=0.3 && <0.5), http-types (==0.8.*), lifted-base (>=0.1 && <0.3), monad-control (>=0.3 && <1.1), mtl (>=2.0 && <2.3), network (>=2.4), network-uri, scientific (>=0.2 && <0.4), temporary (>=1.0 && <2.0), text (>=0.11.3 && <1.3), time (==1.*), transformers (>=0.2 && <0.5), transformers-base (>=0.1 && <1.0), unordered-containers (>=0.1.3 && <0.4), vector (>=0.3 && <0.12), zip-archive (>= && <0.3) [details]
AuthorAdam Curtis
CategoryWeb, Browser, Testing
Home page
Source repositoryhead: git clone git://
UploadedThu Sep 24 02:59:17 UTC 2015 by AdamCurtis
DistributionsLTSHaskell:, NixOS:, Stackage:
Downloads5487 total (343 in last 30 days)
0 []
StatusDocs available [build log]




network-uriGet Network.URI from the network-uri packageEnabledAutomatic



Maintainers' corner

For package maintainers and hackage trustees

Readme for webdriver-


For more information about Selenium itself, see





Installation from Hackage


cabal install webdriver


Installation from this repository


Using cabal-install

cabal install

Using Cabal


runhaskell Setup.hs configure --user
runhaskell Setup.hs build
runhaskell Setup.hs install

For more build options, please refer to the Cabal documentation.



java -jar selenium-server-standalone-*.jar

The server should now be listening at localhost on port 4444.

##Hello, World! With the Selenium server running locally, you're ready to write browser automation scripts in Haskell. Let's start with a simple example.

    {-# LANGUAGE OverloadedStrings #-}
    import Test.WebDriver
    myConfig :: WDConfig
    myConfig = defaultConfig
    main :: IO ()
    main = runSession myConfig $ do
      openPage ""
      searchInput <- findElem (ByCSS "input[type='text']")
      sendKeys "Hello, World!" searchInput

hs-webdriver uses a very simple EDSL implemented within a state monad. Interacting with the remote browser is done via a sequence of commands within this monad. The state monad maintains implicit information about the WebDriver session between commands, so that individual commands only need to specify parameters relevant to the action they perform. If you're new to monads, there are plenty of resources available for learning on the web, but for now you can think of the WD monad as implementing a very simple imperative language operating on an implicit browser session.

Let's take a closer look at each piece of this example.

###Demonic invocations: a bit of boilerplate

    {-# LANGUAGE OverloadedStrings #-}

hs-webdriver uses the Text type to represent Unicode character sequences, which is significantly more efficient than the standard Haskell structure for strings. This directive tells GHC to overload string literals so that they can be used to represent Text values (or, more generally, any other instance of IsString).

    import Test.WebDriver

This line is fairly straightforward; we need to import the library so that we can use it! Most of the basic API is available through the Test.WebDriver module, so this is the only import you should need for most tests. There are other modules that may be of interest for advanced usage; in particular, Test.WebDriver.Commands.Wait provides so-called "implicit waits" as defined by other WebDriver libraries. There are also modules that support custom Firefox and Chrome extensions, but these features are not fully stable.

###Configuring a WebDriver session

    myConfig :: WDConfig
    myConfig = defaultConfig

To configure a new WebDriver session, we use the WDConfig type; this is a record type with various configuration fields. To connect to the Selenium server that we spawned earlier, the defaultConfig is sufficient. By default, the browser is set to Firefox, but that can be changed; the following configuration will use Google Chrome instead of Firefox for our test:

    myConfig :: WDConfig
    myConfig = defaultConfig { wdCapabilities = defaultCaps { browser = chrome } }

Note: To use Google Chrome, you need to install Google's proprietary ChromeDriver in a directory where it can be recognized by Selenium Server (see:

###Initializing tests

    main :: IO ()
    main = runSession myConfig $ do

main is the standard entry point for a Haskell program, defined as a value of type IO a. In order to transform our WD action into an IO action, we use the runSession function, which has the type:

    runSession :: WDConfig -> WD a -> IO a
So we pass to `runSession` our configuration record along with a WebDriver "script" to perform, and it transforms the script into a side-effectful `IO` action. The `WDConfig` record is used to automatically initialize our session with the remote server.

*Note*: `runSession` does not automatically close the session it creates. This is intentional, as you may want to manually inspect the browser state after your code executes. If you want to have the session automatically close, you can use the `finallyClose` function to provide this behavior.
main = runSession myConfig . finallyClose $ do

###Actually writing tests!
  openPage ""
  sendKeys "Hello, World!" searchInput
Interaction with the browser is accomplished via WebDriver "commands", which are just function calls within the `WD` monad. Most of these commands are defined in the `Test.WebDriver.Commands` modules, and are fairly self-explanatory. In this example, `openPage` opens a new URL, and `findElem` searches for a DOM element on the current page which matches the given selector (possible selectors include `ById`, `ByName`, `ByClass`, `ByTag`, `ByLinkText`, `ByCSS`, and `ByXPath`). The DOM Element found by the result of the search is bound to the local variable `searchInput`, and `sendKeys` sends a sequence of emulated keystrokes to the given element.

This example contains all of the basic elements of a simple WebDriver test. For complete documentation on each command, check out the documentation for [Test.WebDriver.Commands](

#Integration with Haskell Testing Frameworks


* [hspec-webdriver](
* [quickcheck-webdriver](


Documentation for hs-webdriver is available on Hackage at <>. You can also generate local HTML documentation from this source revision with the following shell command:

runhaskell Setup.hs haddock

Haddock will generate documentation and save it in `dist/doc/html/webdriver`