diff --git a/lib/playwright/locator.ex b/lib/playwright/locator.ex index 2152a99..bc7170e 100644 --- a/lib/playwright/locator.ex +++ b/lib/playwright/locator.ex @@ -1325,11 +1325,11 @@ defmodule Playwright.Locator do @spec wait_for(t(), options()) :: t() | {:error, Channel.Error.t()} def wait_for(%Locator{} = locator, options \\ %{}) do case Frame.wait_for_selector(locator.frame, locator.selector, options) do - %ElementHandle{} -> - locator - {:error, _} = error -> error + + _ -> + locator end end diff --git a/test/api/locator_test.exs b/test/api/locator_test.exs index dbf1c22..a24e9a2 100644 --- a/test/api/locator_test.exs +++ b/test/api/locator_test.exs @@ -815,6 +815,22 @@ defmodule Playwright.LocatorTest do assert [:ok, %Locator{}] = Task.await_many([setup, check]) end + test "on success with nil return (i.e., a match is found in time) returns the `Locator` instance", %{page: page} do + locator = Locator.new(page, "div > span") + + setup = + Task.async(fn -> + Page.set_content(page, "
target
") + end) + + check = + Task.async(fn -> + Locator.wait_for(locator, %{timeout: 100, state: "hidden"}) + end) + + assert [:ok, %Locator{}] = Task.await_many([setup, check]) + end + test "on failure (i.e., the timeout is reached) returns an `{:error, error}` tuple", %{page: page} do locator = Locator.new(page, "div > span")