Puppeteer Interview Questions

You can get all the links using the tag "a" because all links are build using a tag.

var hrefs = await page.$$eval('a', as => as.map(a => a.href));
Some old application use link instead of a to build links on the page, beware of it

Puppeteer and protractor are not related, Puppeteer and selenium are not related. The only common thing between puppeteer and protractor is NodeJS.

Both Puppeteer and protractor are built on NodeJS platform.

Is it mandatory to have nodeJS for Puppeteer?

Yes, Nodejs is required for the puppeteer to work. Puppeteer is built on NodeJS framework, so most of the puppeteer functions use the Nodejs functions internally, without nodeJS Puppeteer will not work.

If you are from the selenium background, then let's put this as "without JDK java will not work".

NodeJS is similar to JDK.

How to check a checkbox in puppeteer?

You can use the click method of the puppeteer to select a checkbox or a radio button. But using just click checks the already checked checkbox.

So we have to check whether a check box is checked, if a check box is not checked then click the element otherwise ignore it. Please note not sign(!) in the if block

const element = await page.$("locator");
const isCheckBoxChecked = await (await element.getProperty("checked")).jsonValue();
if(! isCheckBoxChecked ){
    await page.click("css locator");
}

Screenshot in Puppeteer

How do you get an attribute of an element using Puppeteer?

You can get the attribute value of an element using getProperty() method from Puppeteer.

const element = await page.$("locator");
const isCheckBoxChecked = await (await element.getProperty("checked")).jsonValue();
What is waitFor() in Puppeteer ?

waitFor() makes the puppeteer sleep for a given amount of time, the time is taken in milliseconds.

await page.waitFor(2000);
Which selector is used in Puppeteer ?

Puppeteer takes the CSS selector as a selector by default.

How do you find more than one element which matches the locator?

You can use the $$mthod to find more than one element using the puppeteer.

await page.$$('locator');

What is a page in Puppeteer ?

It is just a variable, you can name it as anything but as a standard practice, we call it a page. Page is browser tab in the puppeteer perspective. Without the page, you cannot open the browser in puppeteer. When you close the last tab manually it closes the browser in puppeteer just like a manual thing.

WebElement Operations in Puppeteer

This space will be replaced Automatically with ads, so do not delete me. Must be inserted only Above H3, H4, H5
Default timeout in Puppteer ?

The default in puppeteer timeout is 30 seconds

Which framework you are using with puppeteer ?

You can answer based on your project framework, Typically page object model, Cucumber in combination with the page object model.

Can I use Jasmine with Puppeteer ?

Jasmine is a unit testing framework built on Nodejs, majorly used with the protractor. As Puppeteer is also built on Nodejs, you can use the jasmine framework with the puppeteer.

Why it is difficult to use Xpath with Puppeteer ?

By default, the puppeteer converts every locator to a CSS locator, so it is difficult to use XPath, moreover, the puppeteer does not give any function to use the Xpath. In case if you wanted to use XPath then you should use the page.exec() method.

await page.evaluate(() => {
        $x("xpath here").operation
    });

Get Element(s) in Puppeteer

This space will be replaced Automatically with ads, so do not delete me. Must be inserted only Above H3, H4, H5
What is the command to install Puppeteer ?

If you want to install puppeteer along with chromium-browser then you can use the below command.

npm install puppeteer  
    or 
npm i puppeteer

If you just want to install the puppeteer but do not want chromium to be installed then use the below command.

npm install puppeteer
     or
npm i puppeteer
How do you connect the already existing chrome browser with Puppeteer?

You cannot connect to the already existing browser or tab. The browser object in puppeteer gets destroyed after every session.

What is the chromium browser?

Chromium is an engine for a browser, a simple UI built around the engine is a chromium engine. for every application, we receive .exe file similar to that we can also have nodejs package. Puppeteer is nothing but a NodeJS package of chromium engine.

Chrome and MS Edge are built around the chromium engine.

iFrames in Puppeteer

This space will be replaced Automatically with ads, so do not delete me. Must be inserted only Above H3, H4, H5
Is it possible to test Firefox with Puppeteer?

It is possible to work with firefox using the puppeteer.

Install firefox and puppeteer support

npm install puppeteer-firefox​

The remaining code is normal.

const puppeteerFirefox = require('puppeteer-firefox');
(async () => {
  const browser = await puppeteerFirefox.launch({headless:false});
  const page = await browser.newPage();
  await page.goto('https://google.com');
  await page.screenshot({path: 'chercher-tech.png'});
  await browser.close();
})();
Does MS Edge support Puppeteer?

Puppeteer support Chromium, and in 2020 Microsoft announced MS edge is rebuild on chromium. Puppeteer supports MS Edge very well.

What is Command to run the Puppeteer code?

Running puppeteer code similar to running any Nodejs file.

node filename.js
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions