Skip to content

[Bug]: methods fill()/press()/type() doesn't wait element to be focusable, when element inside inert container #42967

Closed

Description

@msgoloborodov

Version

1.60.0

Steps to reproduce

 import { expect, test } from '@playwright/test';                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                     
  test.describe('locator.fill() silently does nothing inside [inert] container', () => {                                                                                                                                                                                                                                                                             
    test.beforeEach(async ({ page }) => {                                                                                                                                                                                                                                                                                                                            
      await page.setContent(`                                                                                                                                                                                                                                                                                                                                        
        <div inert id="locker">                                                                                                                                                                                                                                                                                                                                      
          <input id="target">                                                                                                                                                                                                                                                                                                                                        
        </div>                                                                                                                                                                                                                                                                                                                                                       
        <input id="outside">                                                                                                                                                                                                                                                                                                                                         
      `);                                                                                                                                                                                                                                                                                                                                                            
    });                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                     
    test('fill() resolves successfully but the input stays empty', async ({ page }) => {                                                                                                                                                                                                                                                                             
      const target = page.locator('#target');                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                     
      // All fill() actionability checks pass although the element is inert:                                                                                                                                                                                                                                                                                         
      // visible / enabled / editable do not consider the inert attribute                                                                                                                                                                                                                                                                                            
      // (aria-disabled="true" on the container would make "enabled" fail).                                                                                                                                                                                                                                                                                          
      await expect(target).toBeVisible();                                                                                                                                                                                                                                                                                                                            
      await expect(target).toBeEnabled();                                                                                                                                                                                                                                                                                                                            
      await expect(target).toBeEditable();                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                                                                     
      // This resolves WITHOUT any error...                                                                                                                                                                                                                                                                                                                          
      await target.fill('hello');                                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                                     
      // ...but the value is silently dropped: injected fill does                                                                                                                                                                                                                                                                                                    
      // input.focus() (silently fails inside inert subtree), then                                                                                                                                                                                                                                                                                                   
      // Input.insertText goes to the actual focused element (<body>),                                                                                                                                                                                                                                                                                               
      // and dom.ts returns 'done' without verifying element.value.                                                                                                                                                                                                                                                                                                  
      await expect(target).toHaveValue('');                                                                                                                                                                                                                                                                                                                          
    });                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                     
    test('contrast: click() on the same element waits and times out', async ({ page }) => {                                                                                                                                                                                                                                                                          
      const target = page.locator('#target');                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                     
      // click() is properly blocked: the browser hit-testing skips inert                                                                                                                                                                                                                                                                                            
      // subtrees, so the hit-target check keeps failing.                                                                                                                                                                                                                                                                                                            
      await expect(target.click({ timeout: 3_000 })).rejects.toThrow(/timeout/i);                                                                                                                                                                                                                                                                                    
    });                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                     
    test('contrast: press() sends keystrokes to an unrelated focused element', async ({ page }) => {                                                                                                                                                                                                                                                                 
      const target = page.locator('#target');                                                                                                                                                                                                                                                                                                                        
      const outside = page.locator('#outside');                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                     
      await outside.focus();                                                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                                                                     
      // press() = actionability checks + focus() + key press.                                                                                                                                                                                                                                                                                                       
      // The focus() call silently fails (inert), so the keystroke                                                                                                                                                                                                                                                                                                   
      // lands in whatever was focused before — a field outside the locker.                                                                                                                                                                                                                                                                                          
      await target.press('a');                                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                                                                     
      await expect(target).toHaveValue('');                                                                                                                                                                                                                                                                                                                          
      await expect(outside).toHaveValue('a');                                                                                                                                                                                                                                                                                                                        
    });

    test('contrast: the same input inside [aria-disabled] container is properly waited on', async ({ page }) => {                                                                                                                                                                                                                                                    
      await page.setContent(`                                                                                                                                                                                                                                                                                                                                        
        <div aria-disabled="true" id="locker">                                                                                                                                                                                                                                                                                                                       
          <input id="target">                                                                                                                                                                                                                                                                                                                                        
        </div>                                                                                                                                                                                                                                                                                                                                                       
      `);                                                                                                                                                                                                                                                                                                                                                            
      const target = page.locator('#target');                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                     
      // aria-disabled IS honored: getAriaDisabled() walks up the ancestor                                                                                                                                                                                                                                                                                           
      // hierarchy (roleUtils.ts), so the "enabled" actionability check fails                                                                                                                                                                                                                                                                                        
      // and fill() keeps retrying instead of silently doing nothing.                                                                                                                                                                                                                                                                                                
      await expect(target.fill('hello', { timeout: 3_000 })).rejects.toThrow(/timeout/i);                                                                                                                                                                                                                                                                            
      await expect(target).toHaveValue('');                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                     
      // Emulate unlocking: remove the attribute...                                                                                                                                                                                                                                                                                                                  
      await page.locator('#locker').evaluate(el => el.removeAttribute('aria-disabled'));                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     
      // ...and the same fill() now proceeds and applies the value.                                                                                                                                                                                                                                                                                                  
      // This end-to-end "wait until unlocked" behavior is exactly what                                                                                                                                                                                                                                                                                              
      // [inert] containers are missing (see TODO in roleUtils.isFocusable).                                                                                                                                                                                                                                                                                         
      await target.fill('hello');                                                                                                                                                                                                                                                                                                                                    
      await expect(target).toHaveValue('hello');                                                                                                                                                                                                                                                                                                                     
    });                                                                                                                                                                                                                                                                                                                                                          
  });                              

Expected behavior

fill()/press()/type() should keep retrying while the element is inside an inert subtree (consistent with click() and aria-disabled="true").

Actual behavior

locator.fill() on an element inside an inert container passes all actionability checks (visible/enabled/editable), resolves successfully, but the value is not applied — focus() silently fails on inert elements, Input.insertText goes to the currently focused element.
keyboard.insertText → return 'done', never verifies that the element actually received the value. Worse, locator.press() delivers keystrokes to an unrelated focused element (data corruption in a different field). locator.click() on the same element is properly blocked by the hit-target check, since browser hit-testing skips inert subtrees.

Additional context

No response

Environment

System:
    OS: Windows 10 10.0.19044
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12800H
    Memory: 6.27 GB / 31.69 GB
  Binaries:
    Node: 24.19.0 - C:\Program Files\nodejs\node.EXE
    npm: 11.17.0 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Bash: 5.1.16 - C:\WINDOWS\system32\bash.EXE
  npmPackages:
    @playwright/test: 1.60.0 => 1.60.0 
    playwright-core: 1.60.0 => 1.60.0 
    playwright-msw: 3.0.1 => 3.0.1

Activity

  1. msgoloborodov commented on Sep 28, 2026

    @msgoloborodov
    Author

    Related issue: #36938

  2. github-actions commented on Sep 29, 2026

    @github-actions
    Contributor

    Hi, I'm the Playwright bot and I took a first look at this.

    Reproduced on tip-of-tree (@playwright/[email protected]) in Chromium, Firefox and WebKit, all headless. All three engines behave the same way. When the input sits inside an inert container:

    • fill() succeeds, but the input stays empty.
    • press() / pressSequentially() succeed, but the keys go to whatever element already had focus (#outside ends up with a / ab).
    • click() keeps retrying and times out, as expected, because hit-testing skips inert subtrees.

    This comes from the actionability checks. fill/press check visible/enabled/editable, and none of those look at inert. The injected focus() then fails without an error, and the text goes to whatever element has focus. There's an existing TODO for this in packages/injected/src/roleUtils.ts (isFocusable: "inert" attribute makes the whole subtree not focusable).

    This looks like a real bug. #42125 is a related report that was closed as by design, but there focus moved away during fill() because of page script. Here the target can't receive focus at all, and Playwright could detect that before typing. #36938 (inert elements not being hidden from getByRole) is related but separate.

    Condensed repro
    import { test, expect } from '@playwright/test';
    
    test('fill/press should not succeed on input inside inert container', {
      annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42967' },
    }, async ({ page }) => {
      await page.setContent(`<div inert><input id="target"></div><input id="outside">`);
      await page.locator('#outside').focus();
    
      // Both resolve today; expected to wait/time out like click() does.
      await expect(page.locator('#target').fill('hello', { timeout: 1000 })).rejects.toThrow(/Timeout/);
      await expect(page.locator('#target').press('a', { timeout: 1000 })).rejects.toThrow(/Timeout/);
      await expect(page.locator('#outside')).toHaveValue('');
    });
    What I ran

    @playwright/[email protected], Linux, headless, <div inert><input id="target"></div><input id="outside">:

    Action (timeout 3s) Chromium Firefox WebKit
    fill('hello') resolves, target "" same same
    press('a') with #outside focused resolves, #outside = a same same
    pressSequentially('ab') with #outside focused resolves, #outside = ab same same
    click() times out times out times out

    I didn't re-run on 1.60.0 because tip-of-tree already reproduces it, and I didn't test headed mode.

    Triaged on Linux by the Playwright bot - agent run

  3. hoangtaiki commented on Oct 6, 2026

    @hoangtaiki
    Contributor

    Dmitry Gozman (@dgozman) I see this is assigned to you. If you'd welcome a community PR for it, I'd be happy to send one.

    I have a local fix with tests passing on Chromium, Firefox and WebKit. fill(), clear(), press() and pressSequentially() wait while the target has an [inert] ancestor (crossing shadow roots), then act once it's removed. If it never is, they time out with "element is inert" in the call log, the same way click() already times out on inert elements. fill({ force: true }) skips the check like other actionability checks.

    I've read the history in #36938 / #36947 / #37137 and the closed #42990. This change does not touch roleUtils or locator/aria matching, and unlike #42990 it does not change the "editable" state, so getByRole() and toBeEditable() behave as before. I'd also keep locator.focus() unchanged, since a test may call focus() on an inert element to assert that it can't be focused.

    Two open questions:

    • Should elements outside an open modal <dialog> be treated the same way? My fix only handles the inert attribute.
    • Should the auto-waiting docs list this as a new check?

    Happy to adjust if you'd prefer a different approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions