0

I use puppeteer to get data from page. It have pagination (1,2,3). I need to click on a different button to open new page. But only difference between the buttons is innerText (1,2,3).

Button 1:

<a id="lbnGoToPage" href="javascript:__doPostBack('GoToPage','')">1</a>

Button 2:

<a id="lbnGoToPage" href="javascript:__doPostBack('GoToPage','')">2</a>

Button 3:

<a id="lbnGoToPage" href="javascript:__doPostBack('GoToPage','')">3</a>

How to select button 2 after I have finish get data from page one?

Heretic Monkey
  • 11,078
  • 7
  • 55
  • 112
FlutterFirebase
  • 1,733
  • 4
  • 22
  • 50

1 Answers1

2

You can solve it using an XPath expression using page.$x:

const [link] = await page.$x('//*[@id="lbnGoToPage"][text() = "3"]');
await link.click();

In this case, that would click page "3".

hardkoded
  • 15,907
  • 3
  • 45
  • 56