Below is the code which is trying to execute a browser going to the specified 'rand_url'.
Upon running the script I get the following errors:
TypeError: browser.newpage is not a function
at initBrowser
at async checkout
I am trying to figure out where I've gone wrong in trying to get this to execute in the browser.
Below is the .js
const puppeteer = require('puppeteer');
const rand_url = "URL Redacted for Privacy";
async function initBrowser(){
const browser = await puppeteer.launch({headless:false});
const page = await browser.newpage();
await page.goto(rand_url);
return page;
}
async function addToCart(page){
//SELECT TICKET
await page.$eval("button[class='btn btn-block button-primary ng-scope']", elem => elem.click());
await page.waitfor(2000);
//BRING UP ADD TO CART
await page.$eval("button[class='buyer-type-minicart-button-container primary ng-scope']", elem => elem.click());
await page.waitfor(2000);
//ADD TO CART
await page.$eval("button[class='primary block ng-scope']", elem => elem.click());
await page.waitfor(2000);
//CVV
await page.type("input[id='input-one'", '630');
await page.waitfor(2000);
//CONFIRM AGE
await page.$eval("button[class='data-protection-checkbox data-protection-opt-in-checkbox ng-pristine ng-untouched ng-valid']", elem => elem.click());
await page.waitfor(2000);
//PLACE ORDER
await page.$eval("button[class='btn button-primary ng-binding ng-scope']", elem => elem.click());
await page.waitfor(2000);
}
async function checkout(){
const page = await initBrowser();
await addToCart(page);
}
checkout();
I think, that you have a typo in your method name. Try using
browser.newPage
instead of browser.newpage