How to use page.click

A page object spawned in by using the newPage() method can be used to navigate a page. The click() method clicks on the specified element on the page.

Example Script:

let {newPage, end, except, extract, extractAndSave, store, runStore, waitFor} = __sandbox;
let {params, } = OPTIONS;
(async () => { try {
	// -- START --
	const page = await newPage()
	await page.goto('https://www.example.org')
	await page.click('a')
	await waitFor(3000)
	await page.saveSnapshot('clicked-page')
	await page.close()
	// -- END --
	end()
} catch(e) { except(e) } })();

Scrapex.ai Click Script

Downloadable click Project

Code Breakdown

The given snippet:

  • Opens a new page object using newPage()
  • Navigates to the the url https://www.example.org
  • Clicks the element represented by the selector a. In this case, this will be the only hyperlink in the page.
  • Wait for 3 seconds to conclude navigation
  • Saves a page snapshot for the user to observe after execution
  • close the page.

NOTE: Click method throws an error if the specified selector has more than one matching element on the page.

NOTE: There is a guided counterpart for the click method called clickTag where the latter requires a scraper configured.