Closed Pwntheon closed 5 years ago
For information, the selector i want to add is a lookup by data-attributes like this:
element "data-tab=properties"
should select the element
<div class="tab" data-tab="properties">...</div>
Here is my selector as i wrote it:
module Finders
open canopy.classic
open System.Text.RegularExpressions
open OpenQA.Selenium
exception FinderDoesNotApply of unit
addFinder ( fun dataAttribute f ->
try
if Regex.Match(dataAttribute, "^data-\w{1,}=\w{1,}").Success then
let selectorParts = dataAttribute.Split [|'='|]
let selector = "*[" + selectorParts.[0] + "=\"" + selectorParts.[1] + "\"]"
f(By.CssSelector(selector)) |> List.ofSeq
else
raise (FinderDoesNotApply())
with | ex -> []
)
I figured it out. The documentation is outdated. Adding a third (unused) parameter to the function solves it:
module Finders
open canopy.classic
open System.Text.RegularExpressions
open OpenQA.Selenium
exception FinderDoesNotApply of unit
let dataFinder dataAttribute f _ =
try
if Regex.Match(dataAttribute, "^data-\w{1,}=\w{1,}").Success then
let selectorParts = dataAttribute.Split [|'='|]
let selector = "*[" + selectorParts.[0] + "=\"" + selectorParts.[1] + "\"]"
f(By.CssSelector(selector)) |> List.ofSeq
else
raise (FinderDoesNotApply())
with | ex -> []
Yes, I didnt realize the documentation was out of date. Here is an example:
Thank you for the prompt reply even though i solved the issue.
Loving canpoy :)
I tried adding a finder but i'm getting a type error.
I assumed it was something wrong with my code, but when just pasting the example from the docs i get the same error:
The type 'IWebDriver -> IWebElement list' does not match the type 'IWebElement list'