我用DocumentCompleted来完成。private static readonly string LOGIN_URL = "https://login.taobao.com/member/login.jhtml";void TaobaoWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.ToString().Equals(LOGIN_URL))
{
HtmlElement name = TaobaoWebBrowser.Document.GetElementById("TPL_username_1"); if (name != null)
name.SetAttribute("value", "test"); mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)TaobaoWebBrowser.Document.DomDocument;
mshtml.IHTMLElementCollection inputs = (mshtml.IHTMLElementCollection)doc.all.tags("INPUT");
foreach (mshtml.IHTMLElement ele in inputs)
{
if (ele.getAttribute("name", 0).Equals("TPL_password"))
ele.setAttribute("value", "test", 0);
}
//HtmlElement pwdSpan = TaobaoWebBrowser.Document.GetElementById("J_StandardPwd");
/*
foreach (HtmlElement child in pwdSpan.Children)
{
if (child.TagName.Equals("INPUT") && child.GetAttribute("name").Contains("TPL_password"))
{
((mshtml.IHTMLInputElement)child.DomElement).value = "test";
//child.SetAttribute("value", "test");
break;
}
}
*/
}
}分别使用了C#托管和非托管两种方式做了实现。但是都无法在页面加载完后设置用户名和密码的输入框。高手指点,是什么问题?
{
if (e.Url.ToString().Equals(LOGIN_URL))
{
HtmlElement name = TaobaoWebBrowser.Document.GetElementById("TPL_username_1"); if (name != null)
name.SetAttribute("value", "test"); mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)TaobaoWebBrowser.Document.DomDocument;
mshtml.IHTMLElementCollection inputs = (mshtml.IHTMLElementCollection)doc.all.tags("INPUT");
foreach (mshtml.IHTMLElement ele in inputs)
{
if (ele.getAttribute("name", 0).Equals("TPL_password"))
ele.setAttribute("value", "test", 0);
}
//HtmlElement pwdSpan = TaobaoWebBrowser.Document.GetElementById("J_StandardPwd");
/*
foreach (HtmlElement child in pwdSpan.Children)
{
if (child.TagName.Equals("INPUT") && child.GetAttribute("name").Contains("TPL_password"))
{
((mshtml.IHTMLInputElement)child.DomElement).value = "test";
//child.SetAttribute("value", "test");
break;
}
}
*/
}
}分别使用了C#托管和非托管两种方式做了实现。但是都无法在页面加载完后设置用户名和密码的输入框。高手指点,是什么问题?
解决方案 »
- 一个事件问题
- : System.Xml.XPath.XPathException: 表达式的计算结果必须为节点集。
- 如何改变AutoScrollPosition的值?
- 在vs2005下使用Nant和Nantcontrib做自动构建,出现问题?急
- 如何使TextBox的高度正好显示所有文本内容?
- 我的 netWorkStream = TCPClient.GetStream() 为什么会出错亚?
- 我在程序中必须做一个死循环来检测用户输入的是否事我想要的值,但是为什么程序老是僵在那呢?
- 【tabcontrol】如何用编程方式切换选项卡
- 高分相送,关于C#实现遍历树得到所有树叶,并也能实现给出其中任意一个节点得到其下的树叶?
- [非开发,咨询硬件]大家帮帮忙,看看NAS应该注意选择哪些东西
- treeView 存到数据库 再取出
- 多个条件的linq to sql语句怎么写?
name.SetAttribute("value", "test");经测试,用户名这里是可以自动填入的。但是密码部分就不行。
var elt = webBrowser1.Document.All["Password_Edit_IE"]; if (elt != null)
{
elt.Focus();
SendKeys.Send("aaaa");
}