diff --git a/lib/playwright/locator.ex b/lib/playwright/locator.ex
index bc7170e..99eca22 100644
--- a/lib/playwright/locator.ex
+++ b/lib/playwright/locator.ex
@@ -902,8 +902,18 @@ defmodule Playwright.Locator do
locator(context, "nth=#{index}")
end
- # @spec or(Locator.t(), Locator.t()) :: Locator.t()
- # def or(locator, other)
+ @doc """
+ Returns a new `Playwright.Locator` that matches either of the conditions of the given locators.
+
+ This implements the `or` function for locators, but `or` is not an allowed function name in elixir.
+ """
+ @spec or_(Locator.t(), Locator.t()) :: Locator.t()
+ def or_(%Locator{frame: frame} = locator, %Locator{frame: frame} = other) do
+ new(frame, locator.selector <> ">> internal:or=" <> Jason.encode!(other.selector))
+ end
+ def or_(_, _) do
+ raise ArgumentError, "Locators must belong to the same frame"
+ end
# @spec page(Locator.t()) :: Page.t()
# def page(locator)
diff --git a/test/api/locator_test.exs b/test/api/locator_test.exs
index a24e9a2..34a0dc7 100644
--- a/test/api/locator_test.exs
+++ b/test/api/locator_test.exs
@@ -641,6 +641,57 @@ defmodule Playwright.LocatorTest do
end
end
+ describe "Locator.or_/2" do
+ test "returns a locator that matches either given condition", %{page: page} do
+ page
+ |> Page.set_content("""
+