Search code examples
playwright-java

How to wait for an element has text to present?


I am expecting one locator to have to value Individual. But it is taking slight delay in getting value ..

I saw this in Typescript..

const locator = page.locator('my locator')
await expect(locator).toHaveValue('Individual', {timeout: 20000})

But what is similar to Java. Already i am in a frame and i am looking for one value customer type should be Individual..

        page1.frameLocator("iframe").locator("//*[@text='Last name']/..//input").fill("Auto Newpage");
        page1.frameLocator("iframe").locator("//*[@text='First name']/..//input").fill("Auto Newcontext");
        page1.frameLocator("iframe").locator("text=Save").click();
        page1.frameLocator("iframe").getByText("Identification", new FrameLocator.GetByTextOptions().setExact(true)).click();
        page1.frameLocator("iframe").getByRole(AriaRole.LINK, new FrameLocator.GetByRoleOptions().setName("General")).click();
        page1.frameLocator("iframe").locator("//*[@text='ip.identificationDetails.labels.ipType']/../static-control/p");
    

How to wait for this locator //*[@text='ip.identificationDetails.labels.ipType']/../static-control/p tohaveValue or tohaveText to present as Individual.. just because of slight delay it is returning empty every time. how to overcome and wait for an value and get that text?


Solution

  • Can you please check whether the following works for you?

    assertThat(page.locator("your locator")).hasValue("Individual", new LocatorAssertions.HasValueOptions().setTimeout(20000));