Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var actions = []string{
"Clear",
"Fill",
"FindNth",
"FindMatching",
"FindRegex", // alias of FindMatching
"FindFirst",
"FindLast",
"Find",
Expand Down
2 changes: 2 additions & 0 deletions playwright/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var actionMap = map[string]ActionFunc{
"Fill": FillAction,
"Find": StubExpectAction,
"FindNth": StubExpectAction,
"FindMatching": StubExpectAction,
"FindRegex": StubExpectAction, // alias of FindMatching
"FindFirst": StubExpectAction,
"FindLast": StubExpectAction,
"Check": CheckAction,
Expand Down
16 changes: 15 additions & 1 deletion playwright/playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,24 @@ func tryFindLocator(page playwrightgo.Page, action ExecutorAction) (playwrightgo
return nil, fmt.Errorf(`the parameter N must be a number for FindNth e.g. FindNth "%s" "5"`, selectorOrContent)
}
return loc.Nth(nth), nil
case "FindMatching", "FindRegex":
notExact := false
pattern := action.Content
// check if the content is a regular expression or make it into one
if !strings.HasSuffix(pattern, "/") && strings.HasPrefix(pattern, "/") {
pattern = "/" + action.Content + "/"
}
loc = page.GetByText(pattern, playwrightgo.PageGetByTextOptions{
Exact: &notExact,
})
return loc.First(), nil
case "FindFirst":
return loc.First(), nil
case "FindLast":
return loc.Last(), nil
}
return nil, fmt.Errorf("could not find element using %s", selectorOrContent)
if loc == nil {
return nil, fmt.Errorf("could not find element using %s", selectorOrContent)
}
return loc, nil
}
Loading