-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.js
39 lines (39 loc) · 1.42 KB
/
intro.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const puppeteer=require("puppeteer");
let page;
// console.log("before");
const browseropenPromise=puppeteer.launch({headless:false});
browseropenPromise
.then(function(browser){
//console.log("browser opened");
//currently opened tabs
const pagesArrPromise=browser.pages();
return pagesArrPromise;
}).then(function(browserPages){
page=browserPages[0];
let gotoPromise=page.goto("https://www.google.com/");
return gotoPromise;
}).then(function(){
//waiting for the element to appear on the page
let elementWaitPromise=page.waitForSelector("input[type='text']",{visible:true});
return elementWaitPromise;
}).then(function (){
console.log("reached google home page");
//type any element on the page-->selector
let keysWillBeSendPromise=page.type("input[type='text']","pepcoding");
return keysWillBeSendPromise
}).then(function (){
//page.keyboard to type special characters
let enterWillBePressed=page.keyboard.press("Enter");
return enterWillBePressed;
}).then(function(){
let elementWaitPromise=page.waitForSelector("h3.LC20lb.MBeuO.DKV0Md",{visible:true});
return elementWaitPromise;
}).then(function(){
//mouse
let keysWillBeSendPromise=page.click("h3.LC20lb.MBeuO.DKV0Md");
return keysWillBeSendPromise;
})
.catch(function (err){
console.log(err);
})
// console.log("After");