Selenium - WebDriver

Selenium WebDriver is the most recent version of Selenium which you should use for your automated tests.

You can find more info about WebDriver on Selenium's Documentation page.

Below are some examples on how to use this new protocol with our TestingBot grid.

Ruby and Selenium WebDriver

  1. Install the webdriver gem
    $ gem install selenium-webdriver
  2. Replace API_KEY and API_SECRET with your key and secret, which you can find in the Member area

Code example
#!/usr/bin/env ruby

require 'rubygems'
require 'selenium-webdriver'

caps = Selenium::WebDriver::Remote::Capabilities.firefox
caps.version = "8"
caps.platform = :WINDOWS

driver = Selenium::WebDriver.for(
  :url => "",
  :desired_capabilities => caps) ""
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
puts driver.title

Python and Selenium WebDriver

  1. Install WebDriver
    $ easy_install -U selenium
  2. Replace API_KEY and API_SECRET with your key and secret, which you can find in the Member area

Code example
import unittest
from selenium import webdriver
from testingbot import driver

class Selenium2Test(unittest.TestCase):
    def setUp(self):
        desired_capabilities = webdriver.DesiredCapabilities.FIREFOX
        desired_capabilities['version'] = '8'
        desired_capabilities['platform'] = 'WINDOWS'

        self.driver = webdriver.Remote(

    def test_google(self):
        assert "Google" in self.driver.title

    def tearDown(self):

if __name__ == '__main__':

PHP and selenium webdriver

  1. Download the PHP-webdriver client.

require_once __DIR__ . '/php-webdriver/__init__.php';

	class WebdriverTest extends PHPUnit_Framework_TestCase
	    * @var WebDriverSession
	    protected $_session;

	    public function setUp()
	        $web_driver = new WebDriver("");
	        $this->_session = $web_driver->session("firefox", array('platform' => "WINDOWS", "version" => "latest"));

	    public function tearDown()
			$parts = explode("/", $this->_session->getURL());
			$sessionID = $parts[sizeof($parts) - 1];

			$data = array(
				'session_id' => $sessionID,
				'client_key' => "api_key",
				'client_secret' => "api_secret",
				'test[status_message]' => $this->getStatusMessage(),
				'test[success]' => !$this->hasFailed(),
				'test[name]' => $this->toString()



	    public function testTitle()

	    protected function apiCall(array $postData)
			$data = http_build_query($postData);
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, "" . $postData['session_id']);
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_USERPWD, $postData['client_key'] . ":" . $postData['client_secret']);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            $response = curl_exec($curl);

Java and Selenium webdriver

  1. Install the webdriver at Google code
  2. Replace API_KEY and API_SECRET with your key and secret, which you can find in the Member area

Code example
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;

public class Test {
    public static void main(String[] args) throws Exception {

        DesiredCapabilities capabillities = DesiredCapabilities.firefox();
        capabillities.setCapability("version", "latest");
        capabillities.setCapability("platform", Platform.WINDOWS);

        WebDriver driver = new RemoteWebDriver(
           new URL(""),

        WebElement search = driver.findElement("q"));
        search.sendKeys("Hello, WebDriver");

C# and Selenium webdriver

  1. Download the official C# Client from the Seleniumhq downloads page.
  2. Replace API_KEY and API_SECRET with your key and secret, which you can find in the Member area
using NUnit.Framework;
using System;
using Selenium;
using System.Web;
using System.Text;
using System.Net;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace Test
	public class Test
		private IWebDriver driver;

        public void Init()
            DesiredCapabilities capabillities = DesiredCapabilities.Firefox();
            capabillities.SetCapability(CapabilityType.Version, "8");
			capabillities.SetCapability("api_key", "REPLACE_API_KEY");
            capabillities.SetCapability("api_secret", "REPLACE_API_SECRET");

            driver = new RemoteWebDriver(
                new Uri(""), capabillities);

        public void TestCase()
            StringAssert.Contains("Google", driver.Title);

        public void Cleanup()

Webdriver-backed selenium

This feature gives you the ability to run your existing selenium rc code backed by a webdriver instance
This can help you in migrating to webdriver since it allows you to use the two apis rc and webdriver in the same test
Please see the following example in ruby

#!/usr/bin/env ruby

require "rubygems"
require 'testingbot'
gem "selenium-client"
gem "selenium-webdriver"
require "selenium-webdriver"
require "selenium/client"

selenium = :host    => "",
                                        :port    => 4444,
                                        :url     => "",
                                        :browser => "*webdriver"

caps = {
  :browserName => "iexplore",
  :platform => "WINDOWS"
urlhub = ""
client =
client.timeout = 120

@webdriver = Selenium::WebDriver.for :remote, :url => urlhub, :desired_capabilities => caps, :http_client => client
selenium.start :driver => @webdriver
puts @webdriver.title == selenium.title # WebDriver and RC together "/" # RC
@webdriver.quit # WebDriver