Sundeep Sandhu
Sundeep Sandhu

Reputation: 91

Is it possible to click the back button in the browser using Playwright?

In a browser there's often arrow buttons that go forward and backward in history:

enter image description here

Can these buttons be clicked on via playwright?

There's no elements for them so I was wondering if this is possible...

await navigationObject(page).backButton.click();

Upvotes: 9

Views: 10593

Answers (3)

Jaky Ruby
Jaky Ruby

Reputation: 1654

For Node.js:

await page.goBack()

Or

await page.goForward()

For Python:

await page.go_back()

Or

await page.go_forward()

You can find more info here: https://playwright.dev/docs/api/class-page#page-go-back

Upvotes: 17

tcsnzh
tcsnzh

Reputation: 39

If you are using Camoufox , add enable_cache=True into launch options.

Upvotes: -1

joshua miller
joshua miller

Reputation: 1756

Try the History API:

window.history.back()

and

window.history.forward()

See: https://developer.mozilla.org/en-US/docs/Web/API/History_API

Upvotes: 1

Related Questions