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,687
  • 7
  • 53
  • 122
FlutterFirebase
  • 2,163
  • 6
  • 28
  • 60

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
  • 18,915
  • 3
  • 52
  • 64