Skip to content

Instantly share code, notes, and snippets.

@bertolo1988
Last active June 2, 2016 18:43
Show Gist options
  • Save bertolo1988/28fbecbd81293b76d5b4f85105c58f7e to your computer and use it in GitHub Desktop.
Save bertolo1988/28fbecbd81293b76d5b4f85105c58f7e to your computer and use it in GitHub Desktop.
Grab top questions from stackoverflow.com fidElements example javascript webdriverjs
var timeout = 80000;
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
driver.get('http://stackoverflow.com/');
driver.wait(function() {
return driver.findElement(By.id('h-top-questions')).isDisplayed();
}, timeout);
var mainBar = driver.findElement(By.id('mainbar'));
var questionSelector = 'div.summary > h3 > a';
mainBar.findElements(By.css(questionSelector)).then(function(elements) {
elements.forEach(function(val, idx) {
elements[idx].getText().then(function(text) {
console.log(text);
});
});
});
driver.quit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment