forked from AlexViderman/heroku-selenium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
30 lines (27 loc) · 889 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var webdriver = require('selenium-webdriver');
var express = require('express')
var app = express()
var port = process.env.PORT || 14000;
var By = webdriver.By;
app.get('/test', function (req, res) {
var driver = new webdriver.Builder()
.forBrowser('phantomjs')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
console.log(title);
return title === 'webdriver - Google Search';
});
}, 5000).then(function() {
res.status(200).send('Done');
}, function(error) {
res.status(200).send(error);
});
driver.quit();
});
app.listen(port, function () {
console.log('Example app listening on port: ',port)
});