Skip to content

Instantly share code, notes, and snippets.

@allthingsclowd
Created September 15, 2017 22:55
Show Gist options
  • Save allthingsclowd/6e89fdc5c233cf7424beae5b159030a3 to your computer and use it in GitHub Desktop.
Save allthingsclowd/6e89fdc5c233cf7424beae5b159030a3 to your computer and use it in GitHub Desktop.
This selenium script logs into the Fujitsu K5 Portal and returns all the users email addresses - currently not available via API call
function getNextTable() {
return new Promise(function(resolve,reject) {
driver.findElement(By.xpath('//*[@id="fixed-container"]/div/form/div[2]/div[4]/table[1]/tbody')).getText()
.then(function(result) {
console.log(result);
this.emailList = this.emailList + result;
driver.findElement(By.xpath('//*[@id="paging_table"]/tbody/tr[1]/td[4]/input')).click()
.catch(function(e){
if (e.message.match("no such element")){
resolve(false);
} else {
resolve(false);
driver.close();
throw e;
}
}).then(function(){
driver.wait(function () {
return driver.findElement(By.xpath('//*[@id="fixed-container"]/div/form/div[2]/div[4]/table[1]/tbody'));
}, 10000);
resolve(true);
})})});}
function next() {
return getNextTable()
.then(function(result) {
if (result) {
// run the operation again
return next();
} else {
return result;
}
});
}
console.log('Start');
var emailList;
var webdriver = require('selenium-webdriver');
const until = webdriver.until;
const By = webdriver.By;
const Key = webdriver.Key;
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.manage().timeouts().implicitlyWait(10000);
driver.get('https://s-portal.cloud.global.fujitsu.com/')
.then(function() {
driver.findElement(By.name('login')).click()
.then(function() {
driver.findElement(By.id('keiyakuno')).sendKeys('contractname')
.then(function() {
driver.findElement(By.id('username')).sendKeys('johnDoe')
.then(function() {
driver.findElement(By.id('password')).sendKeys('mypassword')
.then(function() {
driver.findElement(By.id('Submit')).click()
.then(function() {
driver.findElement(By.xpath("//a[contains(.,'User Management')]")).click()
.then(function() {
driver.findElement(By.name('search')).click()
.then(function() {
next()
.then(function(result) {
// process final result here
console.log(this.emailList);
console.log('The End');
driver.close();
}).catch(function(err) {
// process error here
console.log('Crash');
});})})})})})})})});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment