This question may have been asked in the past, but I searched and have not yet found a solution.
I tried all the options that I have found so far, but all in vain. SendKeys does not work, because it does not fill out the file input field with the file to be downloaded. It is not possible to set the input field of the file "SetAttribute" because the value attribute is missing:
thats all.
If I use element.focus (), a pop-up dialog box "select file to upload" appears, and now I do not know how to programmatically fill it in and open it in the file input window.
I want it to be automated so that the user cannot interact with the application. The application should select a file from the hard drive from the given file path and fill in other fields of the form, and then start the download, all using the web browser control in the Windows form application.
No solutions found!
Can anyone help? (This is my first stackoverflow question, so if I am doing something wrong, please direct, I mean, if I am not allowed to post such questions!)
Here is the code:
HtmlElementCollection heCollection = doc.GetElementsByTagName("input");
foreach (HtmlElement heSpan in heCollection)
{
string strType = heSpan.GetAttribute("type");
string strName = heSpan.GetAttribute("name");
if (strType.Equals("file") && strName.Equals("file"))
{
heSpan.Focus();
SendKeys.Send("C:\\1.txt");
}
if (strName.Equals("field_title"))
{
heSpan.InnerText = "1.txt";
}
}
, ( heSpan.focus()), .
heSpan.InvokeMember("click");
/ , , , , .