Skip to content

Instantly share code, notes, and snippets.

@zacharyc
Created June 7, 2012 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zacharyc/2885890 to your computer and use it in GitHub Desktop.
Save zacharyc/2885890 to your computer and use it in GitHub Desktop.
Chromedriver with WebDriverJS
~ $ /Applications/chromedriver
var client = new webdriver.http.CorsClient('http://localhost:9515');
var executor = new webdriver.http.Executor(client);
// Launches a new browser, which can be controlled by this script.
var driver = webdriver.WebDriver.createSession(executor, {
'browserName': 'chrome',
'version': '',
'platform': 'ANY',
'javascriptEnabled': true
});
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click().then(function() {
driver.getTitle().then(function(title) {
if (title !== 'webdriver - Google Search') {
throw new Error(
'Expected "webdriver - Google Search", but was "' + title + '"');
}
});
});
driver.quit();
var client = new webdriver.http.CorsClient('http://localhost:4444/wd/hub');
var executor = new webdriver.http.Executor(client);
// Launches a new browser, which can be controlled by this script.
var driver = webdriver.WebDriver.createSession(executor, {
'browserName': 'chrome',
'version': '',
'platform': 'ANY',
'javascriptEnabled': true
});
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click().then(function() {
driver.getTitle().then(function(title) {
if (title !== 'webdriver - Google Search') {
throw new Error(
'Expected "webdriver - Google Search", but was "' + title + '"');
}
});
});
driver.quit();
<!DOCTYPE html>
<script src="webdriver.js"></script>
<script src="run-driver.js"></script>
~ $ java -jar /<path to selenium>/selenium-server-standalone-<version>.jar -Dwebdriver.chrome.driver=/Applications/chromedriver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment