Search code examples
f#canopy-web-testing

Print HTML Title to the console window using F# + Canopy


I've utilized the following links for reference, but still cannot get my code to print the HTML

<title>This is the title</title>

Using Selenium Code with F# Canopy

http://lefthandedgoat.github.io/canopy/actions.html

The following 3 lines of code do not print what I am expecting (I am attempting C# at the end as another way to do this). What I had expected this to do, was extract the TITLE from my HTML file and print it to the console window. I do not have a "purpose" for this yet, but I was just testing all of the actions available in the documentation.

let theTitle = title()
printfn "Page title is: %s" title()
System.Console.WriteLine("Print the title here: {0}", theTitle);

Solution

  • With this code:

    let title() = @"<title>This is the title</title>"
    printfn "Page title is: %s" (title())
    Page title is: <title>This is the title</title>
    

    I get the expected result. Due to F# type inference restrictions, you need to use a pair of brackets around title().