To run a simple script, for example, google_search.js
const {Builder, By, until} = require('selenium-webdriver');
new Builder()
.forBrowser('firefox')
.build()
.then(driver => {
return driver.get('http://www.google.com/ncr')
.then(_ => driver.findElement(By.name('q')).sendKeys('webdriver'))
.then(_ => driver.findElement(By.name('btnG')).click())
.then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
.then(_ => driver.quit());
});
mkdir testselenium
vim google_search.js
# then paste above codes
npm install selenium-webdriver #it has to be locally installed.
npm install -g geckodriver #when using firefox, the script required geckodriver to be environmental variables.
node google_search.js
If you have selenium-standalone
running, you can send your .js
file to the url as follows:
SELENIUM_REMOTE_URL=http://0.0.0.0:4444/wd/hub node google_search.js