Skip to content

Instantly share code, notes, and snippets.

@akirattii
Created March 13, 2017 04:19
Show Gist options
  • Save akirattii/bf5b93687d7133e80a8548e623b1297d to your computer and use it in GitHub Desktop.
Save akirattii/bf5b93687d7133e80a8548e623b1297d to your computer and use it in GitHub Desktop.
Tweetbot example using Nightmare
// TODO: Change your username/password:
const TW_USER = "<YOUR_USERNAME>";
const TW_PASS = "<YOUR_PASSWORD>";
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true });
nightmare
.goto('https://twitter.com/login/')
.insert('.js-username-field.email-input.js-initial-focus[name="session[username_or_email]"]', TW_USER)
.insert(".js-password-field[name='session[password]']", TW_PASS)
.click('#page-container > div > div.signin-wrapper > form > div.clearfix > button')
.wait(2000)
.goto("https://twitter.com/settings/account")
.evaluate(function() {
return document.querySelector('#username_fieldset > div > p:nth-child(3)').innerText;
})
// open the tweet panel
.click("#global-new-tweet-button > span.Icon.Icon--tweet.Icon--large")
// tweets "hello"
.type('#tweet-box-global', 'hello')
// click to send
.click("#global-tweet-dialog-dialog > div.modal-content > div.modal-tweet-form-container > form > div.TweetBoxToolbar > div.TweetBoxToolbar-tweetButton.tweet-button > button > span.button-text.tweeting-text")
.end()
.then(function(result) {
console.log(result);
})
.catch(function(error) {
console.error('Search failed:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment