Skip to content

Anto0n/puppeteer-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Puppeteer helper

Puppeteer helper - the library of basic functions that will help you to start crawling with Puppeteer fast!

Installation

  1. Clone the project

    git clone git@github.com:Anto0n/puppeteer-helper.git

  2. Install the dependencies

    npm i

Usage example

 import PuppeteerHelper from './index';
 import puppeteer from 'puppeteer';

 // sample of config
 const defaultLaunchOptions = {
   headless: false,

   // most common display resolution
   defaultViewport: {
     width: 1280,
     height: 1024,
   },

   args: [
     '--window-size=1280,984',
   ],
 };

 const run = async () => {
   const browser = await puppeteer.launch(defaultLaunchOptions);
   const puppeteerHelper = new PuppeteerHelper({ browser });
   await puppeteerHelper.visit('https://google.com');
   await puppeteerHelper.delay(5000);
   await puppeteerHelper.close();
 }

 run();

Functions

Title Description
click Click on the element by XPath provided
close Close the browser
delay Suspend for specified time in milliseconds
extractItems Get array of elements out of target element (elementHandle object)
getElementProperty Get the property of html element by property name provided
getUrl Get URL of the target element
getText Get inner text of the target element
getXPath Get element by XPath provided
goBack Return to the previous the page
ifElementPresent check if element is present on the page
pageClose Close current page
scrollViewport Scroll the page until element is present in the viewport
visit Go to website URL
waitForElementToLoad Checks if element is loaded
waitForPageLoad Checks if page is loaded

PROPERTY : string

The HTML element properties

Kind: global constant

visit()

Go to website URL

Kind: global function
Properties

Name Type Description
url string URL of target website

close()

Close the browser

Kind: global function

pageClose()

Close current page

Kind: global function

getXPath()

Get element by XPath provided

Kind: global function
Properties

Name Type Description
selector string XPath selector of the target element

getText() ⇒ string

Get inner text of the target element

Kind: global function
Returns: string - - 'innerText' of the target element
Properties

Name Type Description
selector string XPath selector of the target element
property string Get text property out of the element

getUrl() ⇒ string

Get URL of the target element

Kind: global function
Returns: string - - 'href' of the target element
Properties

Name Type Description
selector string XPath selector of the target element
property string Get URL property out of the element

getElementProperty() ⇒ string

Kind: global function
Returns: string - - property of the target element
Properties

Name Type Description
selector string XPath selector of the target element
property string Get URL property out of the element
index number Index of item

click()

Clicks on the element by XPath selector provided

Kind: global function
Properties

Name Type Description
selector string XPath selector of the target element to click

goBack()

Returns to the previous page

Kind: global function

ifElementPresent() ⇒ Boolean

Checks if element is present

Kind: global function
Properties

Name Type Description
selector string XPath selector of the target element

waitForElementToLoad()

Checks if element is present

Kind: global function
Properties

Name Type Description
selector string XPath selector of the target element
time number time to wait until element is loaded

waitForPageLoad()

Checks if page is loaded

Kind: global function
Properties

Name Type Description
timeout number time to wait until page is loaded

scrollViewport()

Scroll the page until element is present in the viewport

Kind: global function
Properties

Name Type Description
selector string XPath selector of the target element

delay() ⇒ Promise

Suspend for specified time

Kind: global function
Properties

Name Type Description
time string time to suspend

extractItems() ⇒ Array.<Object>

Get array of elements out of target element (elementHandle object)

Kind: global function
Properties

Name Type Description
selector string time to suspend

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published