Skip to content

Commit bdda4ee

Browse files
committed
Fixes Locator.wait_for support for waiting for hidden state elements
1 parent 778e0f4 commit bdda4ee

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/playwright/locator.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -1325,11 +1325,11 @@ defmodule Playwright.Locator do
13251325
@spec wait_for(t(), options()) :: t() | {:error, Channel.Error.t()}
13261326
def wait_for(%Locator{} = locator, options \\ %{}) do
13271327
case Frame.wait_for_selector(locator.frame, locator.selector, options) do
1328-
%ElementHandle{} ->
1329-
locator
1330-
13311328
{:error, _} = error ->
13321329
error
1330+
1331+
_ ->
1332+
locator
13331333
end
13341334
end
13351335

test/api/locator_test.exs

+16
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,22 @@ defmodule Playwright.LocatorTest do
815815
assert [:ok, %Locator{}] = Task.await_many([setup, check])
816816
end
817817

818+
test "on success with nil return (i.e., a match is found in time) returns the `Locator` instance", %{page: page} do
819+
locator = Locator.new(page, "div > span")
820+
821+
setup =
822+
Task.async(fn ->
823+
Page.set_content(page, "<div><span style='visibility: hidden;'>target</span></div>")
824+
end)
825+
826+
check =
827+
Task.async(fn ->
828+
Locator.wait_for(locator, %{timeout: 100, state: "hidden"})
829+
end)
830+
831+
assert [:ok, %Locator{}] = Task.await_many([setup, check])
832+
end
833+
818834
test "on failure (i.e., the timeout is reached) returns an `{:error, error}` tuple", %{page: page} do
819835
locator = Locator.new(page, "div > span")
820836

0 commit comments

Comments
 (0)