Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] page.wait_for_load_state() not working after click() #24125

Closed
1 task done
h-e-l-o opened this issue Jul 10, 2023 · 4 comments
Closed
1 task done

[BUG] page.wait_for_load_state() not working after click() #24125

h-e-l-o opened this issue Jul 10, 2023 · 4 comments

Comments

@h-e-l-o
Copy link

h-e-l-o commented Jul 10, 2023

System info

  • Playwright Version: [v1.35.0]
  • Operating System: [Debian Bookworm]
  • Browser: [Chromium]
  • Other info: Python 3.11

Source code

  • I provided exact source code that allows reproducing the issue locally.
from playwright.sync_api import sync_playwright

import time
import sys

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    page = browser.new_page()
    page.goto("https://paste.ononoki.org/")

    page.locator('xpath=//textarea[@id="message"]').type("HELLO WORLD")
    page.get_by_role("button", name="send").click()
    page.wait_for_load_state()
    print(page.url)

    time.sleep(10)
    browser.close()
sys.exit()

Steps

  • [Run the test]

Expected

The actual target URL (ie. where the button takes you) should be printed.

Actual

The code prints https://paste.ononoki.org/ rather than the target url (eg something like https://paste.ononoki.org/?18f7b2d1ee31024c#BMXkAs1MzWBm5Jot4Yc3XPGFH9sTDXFeFBsBneusvAaZ).

page.wait_for_load_state("domcontentloaded") has no effect either.

@mxschmitt
Copy link
Member

instead of waiting for a load state, you want this instead:

    with page.expect_navigation():
        page.get_by_role("button", name="send").click()

When using that it works for me.

@h-e-l-o
Copy link
Author

h-e-l-o commented Jul 11, 2023

Ok this looks like a good workaround, however is the original method supposed to be working or not?

@mxschmitt
Copy link
Member

It returns immediately because there is load event already fired on the page before the actual navigation has happened. So this works as intended but I agree that it might be confusing. Wait for navigation is what you want here.

@h-e-l-o
Copy link
Author

h-e-l-o commented Jul 11, 2023

Thanks!

@h-e-l-o h-e-l-o closed this as completed Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants