-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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]check() method in Playwright Python is not working #15420
Comments
In the error message above, the line that reads:
indicates there is an element on top of the If you inspect the DOM of the sample page where that label element is, you'll see the "checkbox" is implemented like:
Simplified, it's like: https://jsfiddle.net/12pdg56z/16/ (and if you change opacity of the actual input you can see it visually https://jsfiddle.net/0uxL2fez/). Let me review with the team what the expected behavior here should be. As a workaround, for this specific element, you can set |
This comment was marked as outdated.
This comment was marked as outdated.
Your selector With this, you won't need def get_days_locator(day):
return f"//label[text()='{day}']/preceding-sibling::input" to: def get_days_locator(day):
return f"//label[text()='{day}']" or more idiomatically with Playwright, just do: page.locator('label', has_text='Monday').check() The following works: with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context()
page =context.new_page()
page.goto('https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407')
page.locator('label', has_text='Monday').check()
assert page.locator(get_days_locator("Monday")).is_checked() Let us know if this makes sense! Aside: Playwright has auto-waiting built-in, so you shouldn't need |
Hello, Thanks again. |
@soumya-kar When I run the broken snippet below, it times out after about 30seconds and prints the logs.
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context()
page =context.new_page()
page.goto('https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407')
page.locator("//label[text()='Monday']/preceding-sibling::input").check() #BROKEN This also happens when running through pytest:
def test_it_timesout(page):
page.goto('https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407')
page.locator("//label[text()='Monday']/preceding-sibling::input").check() # BROKEN Can file a new issue with a repro for the infinite waiting you are observing? Thanks! |
Context:
Code Snippet
Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally. For example:
import time
from playwright.sync_api import Page
def test_check_checkbox(page: Page) -> None:
page.goto("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")
time.sleep(5)
page.locator(get_days_locator("Monday")).check()
assert page.locator(get_days_locator("Monday")).is_checked()
def get_days_locator(day):
return f"//label[text()='{day}']/preceding-sibling::input"
Describe the bug
When I run the above code with Pytest. Browser gets launched. Url is loaded. After that, it just trying to check the checkbox but unable to do it. Doing retrying multiple times
E retrying click action, attempt #14
E waiting 500ms
E waiting for element to be visible, enabled and stable
E element is not stable - waiting...
E element is visible, enabled and stable
E scrolling into view if needed
E done scrolling
E performing click action
E Monday intercepts pointer events
E retrying click action, attempt #15
E waiting 500ms
The text was updated successfully, but these errors were encountered: