Search code examples
f#canopycanopy-web-testing

F# Canopy: Not picking up certain page elements


I am a newbie to F# Canopy and am testing out inputting a date into input boxes at https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm. When running the Canopy code below, I receive a "user-unhandled" exception stating "canopy.types.ConaopyElementNotFoundException: 'can't find element id=priceDate.month'" although the element can be seen with the page source as well as the Selenium Page Object Generator and Selenium Object Finder extensions for Chrome. It seems that for some page objects, Canopy doesn't pick up on those elements... or I am missing something. Any thoughts?

open System
open canopy
open canopy.runner.classic
open canopy.configuration
open canopy.classic

[<EntryPoint>]
let main argv =
    canopy.configuration.chromeDir <- System.AppContext.BaseDirectory

    //start an instance of chrome
    start chrome

    "testing UST prices" &&& fun _ ->
        //this is an F# function body, it's whitespace enforced

        //go to url
        url "https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm"

        click "id=priceDate.month"
        "id=priceDate.month" << "3"
        click "id=priceDate.day"
        "id=priceDate.day" << "31"
        click "id=priceDate.year"
        "id=PriceDate.year" << "2020"

        click "Show Prices"
        click "CSV Format"


    //run all tests
    run()

    printfn "press [enter] to exit"
    System.Console.ReadLine() |> ignore

    quit()

    0

Solution

  • Looks like you are writing the XPath wrong.

    This will work

     click "//*[@id='priceDate.month']"
            "//*[@id='priceDate.month']" << "3"
     click "//*[@id='priceDate.day']"
            "//*[@id='priceDate.day']" << "31"
     click "//*[@id='priceDate.year']"
            "//*[@id='priceDate.year']" << "2020"
    

    A solution to find the correct XPath is by using developer tool in Chrome. Right click the element and Copy -> Copy XPath