Created
September 29, 2013 20:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.