How to Refresh Page in Playwright Java

Profile picture for user arilio666

You can use the page to refresh a page in Playwright using java.reload() method, which will reload the current page.

Syntax:

page.reload();
page.reload(options);

Arguments:

timeout: maximum operation time in milliseconds. The default is 0.
waitUntil: load|domcontentloaded|commit|networkIdle

domcontentloaded: When this event is fired, consider the operation finished.
load: When this event is fired, assess the operation to finish.
networkIdle: When there is no connection for at least 500ms, consider this operation completed.
commit: Consider it ended when the network loads up, and docs start loading.

Example:

        page.navigate("http://autopract.com/selenium/popup/");
        page.reload();
        page.locator("//a[normalize-space()='JQuery Popup Model']").click();
        String textContent = page.locator("//p[normalize-space()='This is Sample Popup.']").textContent();
        System.out.println(textContent);
        
  • Here we used the reload to refresh the page as soon as it is navigated to load the webpage's contents clearly and visible after it reloads.