Skip to content
This repository has been archived by the owner on Jan 17, 2020. It is now read-only.

Fix WithLabel selector #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/Moonshine/Selector.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import Data.Maybe (Maybe(..))
import Data.Newtype (un)
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..))
import Data.XPath.Builder ((==.), (|.))
import Data.XPath.Builder ((==.), (|.), (</>))
import Data.XPath.Builder as X
import Data.XPath.Builder.Function as XF
import Lunapark as LP
import Lunapark.Error as LE
import Lunapark.Types as LT
Expand Down Expand Up @@ -131,13 +132,19 @@ runSelector = R.interpretRec (R.on _selector handleSelector R.send)
in map cont $ LP.findElement $ LT.ByXPath $ titled |. ariaLabelled
WithLabel txt cont →
let
titled =
labelled =
X.absDescendantOrSelf
(X.withPredicate X.any (X.attr ( "title") ==. txt))
ariaLabelled =
((X.withPredicate
(X.named "label")
(XF.startsWith X.text txt) </> X.any) :: X.Path)
labelledBy =
X.absDescendantOrSelf
(X.withPredicate X.any (X.attr ( "aria-label") ==. txt))
in map cont $ LP.findElement $ LT.ByXPath $ titled |. ariaLabelled
(X.withPredicate
X.any
(X.withPredicate
(XF.id (X.attr "aria-labelledby"))
(X.text ==. txt)))
in map cont $ LP.findElement $ LT.ByXPath $ labelled |. labelledBy
Before el tested cont → do
res ← isBefore el tested
if res then pure $ cont tested else RE.throw
Expand Down