I press a button after a webpage loads into my WebBrowser control. How do I know it's loaded? I wait a significant amount of time to be sure.
Here is one version of the button code :
var elementsx = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement file in elementsx)
{
if (file.GetAttribute("type") == "file")
{
listBox1.Items.Add(file.Style.ToString());
file.Focus();
file.InvokeMember("Click");
SendKeys.Send(@"C:\Users\John\Desktop\test1\blue-book-motorcycle.jpg" + "{ENTER}");
}
}
Here is another:
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument;
// ################################################################################
//get the title textbox
IHTMLElementCollection inputer = (IHTMLElementCollection)doc.getElementsByTagName(@"input");
foreach (IHTMLElement element in inputer)
{
listBox1.Items.Add(element.style.cssText + " ||| " + element.getAttribute("type").ToString() + "%%%" + element.className);
//we also get other textboxes with similar class names that begin with
//gwt-TextBox so we test for it.
if(element.style.cssText=="height: 0px; visibility: hidden; position: absolute;" &&
element.getAttribute("type").ToString()=="file")
{
++i;
if(i==3)
{
element.click();
SendKeys.Send(@"C:\Users\John\Desktop\test1\blue-book-motorcycle.jpg" + "{ENTER}");
}
}
//webBrowser1.Update();
}
They both fail in the sense that, even though the open dialog appears , no keys are entered into the open dialog text box and it just sits there doing nothing.
Also, if I click the CANCEL button into the opendialog I get the following error: ":\Users\john\Desktop\test1\blue-book-motorcycle.jpg The filename is not valid" . So, the opendialog textbox stripped the "C" from my keys. What's the problem? I ran it as admin also. Fail!!!