Reputation: 25
(node:15348) UnhandledPromiseRejectionWarning: Error: Execution context was destroyed, most likely because of a navigation.
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
page.goto("https://www.google.com/maps/place/Faruk+G%C3%BCll%C3%BCo%C4%9Flu+-+Sunny/@41.0298046,28.7909262,13z/data=!4m8!1m2!2m1!1sfaruk+gulluoglu!3m4!1s0x14caa4f77579848b:0x37c42d8b0cecc146!8m2!3d41.0298046!4d28.8151116");
page.waitFor
const seeAllReviewsButton = "#pane > div > div.widget-pane-content.scrollable-y > div > div > div:nth-child(45) > div > div > button > span";
page.click(seeAllReviewsButton);
I can't navigate to Google Maps Link Of A Business.
Upvotes: 0
Views: 469
Reputation: 2365
There are few corrections needed: You need to await page.goto
, page.waitFor
, and page.click
methods. And most importantly page.waitFor()
is a method and it takes string or number or function as arguments and all of these methods return a promise. So they need to be awaited or do then on it.
Upvotes: 1
Reputation: 2383
You need to use await
before page.goto
, page.waitFor
and page.click
because it return Promise
. and use { waitUntil: "domcontentloaded" }
with page.goto
to wait for DOM
. then I fix seeAllReviewsButton
selector.
The code below works fine with me.
const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(
"https://www.google.com/maps/place/Faruk+G%C3%BCll%C3%BCo%C4%9Flu+-+Sunny/@41.0298046,28.7909262,13z/data=!4m8!1m2!2m1!1sfaruk+gulluoglu!3m4!1s0x14caa4f77579848b:0x37c42d8b0cecc146!8m2!3d41.0298046!4d28.8151116",
{ waitUntil: "domcontentloaded" }
);
const seeAllReviewsButton =
"#pane > div > div.widget-pane-content.scrollable-y > div > div > div.section-hero-header-title > div.section-hero-header-title-top-container > div.section-hero-header-title-description > div.section-hero-header-title-description-container > div > div.gm2-body-2.section-rating-line > span:nth-child(3) > span > span:nth-child(1) > span:nth-child(2) > span:nth-child(1) > button";
await page.waitForSelector(seeAllReviewsButton);
await page.click(seeAllReviewsButton);
})();
Upvotes: 0