Search code examples
javaplaywrightplaywright-java

Playwright - type or fill not working as expected


I am automating UI using PlayWright and Java. I have a search box in the iFrame. When I enter the text in it, I get the tool tip: Search for <number_entered> by. However, when I enter the number using PlayWright's .fill() or .type() the UI does not identify the text entered and displays message: Search for "" by (refer below screenshot) implying that the UI thinks no text is entered.

enter image description here

When I enter the same text manually it just works fine. The UI identfies the text entered.

Code:

Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false).setHandleSIGINT(false));
Page page = browser.newPage();
FrameLocator frame = page.frameLocator("#iFrameID");
Locator searchBox = frame.locator("#searchBox");
searchBox.click();
searchBox.fill ("454545487");
Locator searchIcon = frame.locator(".searchContainer");
searchIcon.click()

Solution

  • Try using:

    await searchBox.pressSequentially('454545487')
    

    This method will emit all the necessary keyboard events, with all the keydown, keyup, keypress events in place. You can even specify the optional delay between the key presses to simulate real user behavior.