Created
July 19, 2018 12:50
-
-
Save Wikiko/2b48c1a03ae16c919f891759d2e3632a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const webdriver = require('selenium-webdriver'); | |
const { By, until, keys } = webdriver; | |
let chrome = require('selenium-webdriver/chrome'); | |
let options = new chrome.Options(); | |
options.addArguments("user-data-dir=c:/Users/Derex/AppData/Local/Google/Chrome/User Data/DC/"); | |
let driver = new webdriver.Builder() | |
.forBrowser('chrome') | |
.setChromeOptions(options) | |
.build(); | |
driver.get('http://www.facebook.com/groups/'); | |
//COM AWAIT | |
let getLinksGroups = (async () => { | |
return new Promise(async resolve => { | |
let liDir = await driver.findElement({ css: '.uiList.mam._509-._4ki._4ks' }); | |
let nLi = await liDir.findElements({ xpath: './li' }); | |
let nLinks = await Promise.all(nLi.map(async (elem, index) => { | |
return await elem.findElements({ css: 'li>ul>li' }); | |
})) | |
return await nLinks; | |
}) | |
}); | |
// Com promises | |
const getLinksGroups2 = () => new Promise((resolve, reject) => { | |
driver | |
.findElement({ css: '.uiList.mam._509-._4ki._4ks' }) | |
.then(liDir => liDir.findElements({ xpath: './li' })) | |
.then(nLi => Promise.all(nLi | |
.map(element => element.findElements({ css: 'li>ul>li' })))) | |
.then(resolve) | |
.catch(reject); | |
}); | |
// possivelmente funcione por que o WebElement que | |
// é devolvido pelo selenium deixa usar o findElements diretamente no retorno do findElement | |
const talvezFuncioneGetLinkGroups = () => new Promise((resolve, reject) => { | |
driver | |
.findElement({ css: '.uiList.mam._509-._4ki._4ks' }) | |
.findElements({ xpath: './li' }) | |
.then(nLi => Promise.all(nLi | |
.map(element => element.findElements({ css: 'li>ul>li' })))) | |
.then(resolve) | |
.catch(reject); | |
}); | |
driver.wait(until.elementLocated({ css: '._38my' })).then(() => { | |
getLinksGroups().then((asd) => { | |
}) | |
}); | |
setTimeout(() => { | |
driver.quit(); | |
}, 15000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment