[英]F# Canopy: Not picking up certain page elements
我是 F# Canopy 的新手,我正在測試在https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm的輸入框中輸入日期。 運行下面的 Canopy 代碼時,我收到一個“用戶未處理”異常,說明“canopy.types.ConaopyElementNotFoundException: 'can't find element id=priceDate.month'”雖然可以在頁面源中看到該元素以及Selenium 頁面 Object 發電機和 Selenium Z497031794414A552435F90151AC3 查找器擴展似乎對於某些頁面對象,Canopy 無法識別這些元素……或者我遺漏了一些東西。 有什么想法嗎?
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
看起來你寫錯了 XPath。
這將起作用
click "//*[@id='priceDate.month']"
"//*[@id='priceDate.month']" << "3"
click "//*[@id='priceDate.day']"
"//*[@id='priceDate.day']" << "31"
click "//*[@id='priceDate.year']"
"//*[@id='priceDate.year']" << "2020"
找到正確的 XPath 的解決方案是使用 Chrome 中的開發人員工具。 右鍵單擊元素並復制 -> 復制 XPath
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.