SHARE
TWEET

Untitled

a guest Mar 17th, 2018 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global.puppeteer = require('puppeteer');
  2. require('css.escape');
  3.  
  4. global.username = 'LEA1';
  5. global.password = '1kniliboM';
  6. global.usernameSelector = '#ctl00_ContentPlaceHolder1_txtuser';
  7. global.passwordSelector = '#ctl00_ContentPlaceHolder1_txtpass';
  8. global.loginButtonSelector = '#ctl00_ContentPlaceHolder1_txtlogin';
  9. global.dropDownSelector = `#${CSS.escape('x:414412543.4:mkr:ButtonImage')}`;
  10. global.dateFromSelector = `#${CSS.escape('x:1580843406.0:mkr:3')}`;
  11. global.dateToSelector = `#${CSS.escape('x:2114782583.0:mkr:3')}`;
  12. globalReturnMsg = `#${CSS.escape('ctl00_ContentPlaceHolder1_lblmsger')}`;
  13. global.exportButtonSelector = '#ctl00_ContentPlaceHolder1_btnexport';
  14. global.responseReceived = false;
  15. const Type = process.argv[2];
  16. const Num = process.argv[3];
  17. const DatF = process.argv[4];
  18. const DatT = process.argv[5];
  19.  
  20. (async () => {
  21.  
  22.     const browser = await puppeteer.launch({args: ['--no-sandbox']});
  23.     const page = await browser.newPage();
  24.     await page.goto('http://retriever/#');
  25.     await page.type(usernameSelector, username);
  26.     await page.type(passwordSelector, password);
  27.     await page.screenshot({path: 'credentials.png'});
  28.     await page.click(loginButtonSelector);
  29.     await page.waitForNavigation({waitUntil: 'load'});
  30.     await page.screenshot({path: 'afterlogin.png'});
  31.     const selector = '#' + CSS.escape('x:414412543.4:mkr:ButtonImage');
  32.     console.log(selector);
  33.     var waitTill = new Date(new Date().getTime() + 1000);
  34.     while(waitTill > new Date()){}
  35.     if (Type > 1)
  36.     {
  37.     await page.click(dropDownSelector);
  38.         await page.keyboard.press('ArrowDown');
  39.     }
  40.     if (Type == 2) //BParty
  41.     {
  42.         await page.click(dropDownSelector);
  43.         await page.keyboard.press('ArrowDown');
  44.     var waitTill = new Date(new Date().getTime() + 1000);
  45.     while(waitTill > new Date()){}
  46.     }
  47.     else if  (Type == 3) //IMEI
  48.     {
  49.         await page.click(dropDownSelector);
  50.         await page.keyboard.press('ArrowDown');
  51.     var waitTill = new Date(new Date().getTime() + 1000);
  52.     while(waitTill > new Date()){}
  53.     await page.click(dropDownSelector);
  54.         await page.keyboard.press('ArrowDown');
  55.     var waitTill = new Date(new Date().getTime() + 1000);
  56.     while(waitTill > new Date()){}
  57.     }
  58.    
  59.     await page.type('#ctl00_ContentPlaceHolder1_txtAparty', Num);
  60.     await page.type(dateFromSelector, DatF);
  61.     await page.type(dateToSelector, DatT);
  62.     await page.screenshot({path: 'afterdatetype.png'});
  63.    
  64.     page.on('request', request => {
  65.         console.log(request._headers);
  66.     });
  67.  
  68.     page.on('response', async (response) => {
  69.         console.log("\nBEGIN RESPONSE\n");
  70.         //console.log('\n\nResponse');
  71.         //console.log(response.headers());
  72.     //var rtrn = await page.evaluate(() => {
  73.     //return elementHandle(ReturnMsg).toString();
  74.     //});
  75.         //console.log(rtrn);
  76.     console.log("\nEND RESPONSE\n");
  77.     responseReceived = true;
  78.     });
  79.  
  80.     await page._client.send('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: 'c:\\puppeteer\\' });
  81.     //console.log('\ndownload behavior set');
  82.     await page.click(exportButtonSelector);
  83.     await page._client.send('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: 'c:\\puppeteer\\' });
  84.     await page.screenshot({path: 'afterclickingexport.png'});
  85.     console.log('\ndownload Completed');
  86.     return 1;
  87. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top