Puppeteer helper
- the library of basic functions that will help you to start crawling with Puppeteer fast!
-
Clone the project
git clone git@github.com:Anto0n/puppeteer-helper.git
-
Install the dependencies
npm i
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();
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 |
The HTML element properties
Go to website URL
Kind: global function
Properties
Name | Type | Description |
---|---|---|
url | string |
URL of target website |
Close the browser
Close current page
Get element by XPath provided
Kind: global function
Properties
Name | Type | Description |
---|---|---|
selector | string |
XPath selector of the target element |
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 |
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 |
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 |
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 |
Returns to the previous page
Checks if element is present
Kind: global function
Properties
Name | Type | Description |
---|---|---|
selector | string |
XPath selector of the target element |
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 |
Checks if page is loaded
Kind: global function
Properties
Name | Type | Description |
---|---|---|
timeout | number |
time to wait until page is loaded |
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 |
Suspend for specified time
Kind: global function
Properties
Name | Type | Description |
---|---|---|
time | string |
time to suspend |
Get array of elements out of target element (elementHandle object)
Kind: global function
Properties
Name | Type | Description |
---|---|---|
selector | string |
time to suspend |