Search code examples
pythonplaywrightplaywright-python

How to type F5 to refresh a page using Playwright Python


I'm trying to refresh a webpage using F5 key. I know I can use:

self.page.reload()

But this is not a good solution for my problem. How to make the page to be refreshed using the F5 key? My code doesn't refresh the page and I don't know why.

self.page.keyboard.press('F5')

Solution

  • afaik, playwright uses a virtual keyboard and does not exactly send the same signal as a real keyboard to the browser application.

    consider going native and using something closer to kernel like pyautogui, after you've focused you window:

    import pyautogui
    pyautogui.press('f5')