简体   繁体   中英

How to upload a image file to a web site through webbrowser with VB.Net

I'm trying to fill website forms and I can do it with textbox, checkbox, radios, select-combobox, all by code but when I try to upload a image file I only can do it by keyboard pulsation simulation (SendKeys).

Is there any way to achieve it using only code? I need to know because I want that my application runs in background.

If its impossible by security reasons, can anybody show me a link with documentation explaining why?

Thank you all.

This is my working code to upload image:

 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

You can use the SetAttribute() method to set the value attribute of the input-tag.

elemento.SetAttribute("value", "                 " & Form2.Label6.Text & "\t\t\n")

\\t is the tab character, and \\n the a new line character (assuming that you are inputting them, if you are actually trying to move the focus and click something please give me more information about that object).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM