【发布时间】:2014-05-16 16:34:18
【问题描述】:
在网页加载到我的 WebBrowser 控件后,我按下了一个按钮。我怎么知道它已加载?我要等很长时间才能确定。
这是一个版本的按钮代码:
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}");
}
}
这是另一个:
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();
}
它们都失败了,即使出现了打开的对话框,也没有在打开的对话框文本框中输入任何键,它只是坐在那里什么都不做。
另外,如果我在 opendialog 中单击 CANCEL 按钮,我会收到以下错误: ":\Users\john\Desktop\test1\blue-book-motorcycle.jpg 文件名无效" .因此,opendialog 文本框从我的键中删除了 "C"。有什么问题?我也以管理员身份运行它。失败!!!
【问题讨论】:
-
您不能将文本插入该对话框,这是一种反恶意软件对策。
-
这是您想要实现的目标吗? stackoverflow.com/q/18687876/1768303
标签: c# .net httpwebrequest webbrowser-control webclient