Skip to content

Instantly share code, notes, and snippets.

@shane-reaume
Created September 29, 2013 20:06
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 shane-reaume/6756053 to your computer and use it in GitHub Desktop.
Save shane-reaume/6756053 to your computer and use it in GitHub Desktop.
Node headless (phantom.js) connection and search with the selenium-webdriver library
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.phantomjs()).
build();
driver.get('http://www.duckduckgo.com');
driver.findElement(webdriver.By.id('search_form_input_homepage')).sendKeys('nodejs');
driver.findElement(webdriver.By.id('search_button_homepage')).click();
var g = driver.getCurrentUrl();
g.then(function(u) {
console.log("URL is: " + u);
});
@shane-reaume
Copy link
Author

Make sure you have slenium-webdriver installed using npm or in my case I use the WebStorm (PhpStorm, IntelleJ) installer and have the API phantom.exe in the root of your project, or make alterations to PATH. You can also use other API's for Android, Chrome or Firefox by changing the Capabilities and adding the .exe file.

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