[英]How to upload a image file to a web site through webbrowser with VB.Net
我正在嘗試填寫網站表單,並且可以通過代碼,文本框,復選框,單選框,選擇組合框來完成此操作,但是當我嘗試上傳圖像文件時,只能通過鍵盤跳動模擬(SendKeys)來完成。
有什么方法可以僅使用代碼來實現? 我需要知道,因為我希望我的應用程序在后台運行。
如果由於安全原因無法實現,誰能向我顯示說明原因的文檔鏈接?
謝謝你們。
這是我上傳圖片的工作代碼:
For Each elemento As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If elemento.GetAttribute("name") = "ad_picture_a" Then
elemento.Focus()
SendKeys.SendWait(" " & Form2.Label6.Text & "{TAB}" & "{TAB}" & "{ENTER}")
Exit For
End If
Next
您可以使用SetAttribute()
方法來設置輸入標簽的value
屬性。
elemento.SetAttribute("value", " " & Form2.Label6.Text & "\t\t\n")
\\t
是制表符, \\n
是換行符(假設您正在輸入它們,如果您實際上是在嘗試移動焦點並單擊某些內容,請向我提供有關該對象的更多信息)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.