使用F#和Canopy进行现场抓取

Mar*_*tin 3 f# canopy-web-testing

我正在尝试使用F#和Canopy编写一个简单的刮刀(参见http://lefthandedgoat.github.io/canopy/).我试图从类".application-tile"中提取所有元素的文本.但是,在下面的代码中,我得到以下构建错误,我不明白.

This expression was expected to have type
    OpenQA.Selenium.IWebElement -> 'a    
but here has type
    OpenQA.Selenium.IWebElement
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?谢谢!

open canopy
open runner
open System

[<EntryPoint>]
let main argv = 
    start firefox

    "taking canopy for a spin" &&& fun _ ->
        url "https://abc.com/"

        // Login Page
        "#i0116" << "abc@abc.com"
        "#i0118" << "abc"
        click "#abcButton"

        // Get the Application Tiles -- BUILD ERROR HAPPENS HERE
        elements ".application-tile" |> List.map (fun tile -> (tile |> (element ".application-name breakWordWrap"))) |> ignore

    run()
Run Code Online (Sandbox Code Playgroud)

lef*_*oat 5

open canopy
open runner

start firefox

"taking canopy for a spin" &&& fun _ ->
    url "http://lefthandedgoat.github.io/canopy/testpages/"

    // Get the tds in tr
    let results = elements "#value_list td" |> List.map read

    //or print them using iter
    elements "#value_list td" 
        |> List.iter (fun element -> System.Console.WriteLine(read element))

run()
Run Code Online (Sandbox Code Playgroud)

那应该做你想要的.

冠层具有称为"读取"的功能,它接收选择器或元素.由于您拥有来自"elements"选择器"'的所有内容,因此您可以在列表中映射读取.

List.map接受一个函数,运行它,并返回一个结果列表.(在C#中它的like元素.Select(x => read(x))List.iter与.foreach相同(x => System.Console.Writeline(read(x))