如何在WebBroswer控件中点击"这个"网页中的提交按钮
<html>
<head>例子网页</head>
<body>
<form method='post' action='http://Gold.8848.com/JiFenWeb/LoginPage.aspx'>
用户名:<input name='UserID' type='text'>
密码:<input name='UserPwd' type='password'>
<input type='image' src='http://www.xxxx.com.cn/images/login.gif'>
</form>
</body>
</html>用类似以下的代码无法点击那个登录按钮(也就是 login.gif 图片按钮)
MSHTML::IHTMLElementCollection* pColl = NULL;
hr=spHtmlDocument->get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
{
MSHTML::IHTMLElement* pElem = NULL;
disp=pColl->item( name, index );
if(disp==NULL)
hr=E_FAIL;
else
{
hr=disp->QueryInterface(&pElem);
}......
}我觉得好像 item函数必须要指定 网页元素的"名称(name)"或者"索引号(index)"
但是在IE中这个网页却是可以点击提交的.请问如何用程序实现,点击这个 登录按钮呢?
<html>
<head>例子网页</head>
<body>
<form method='post' action='http://Gold.8848.com/JiFenWeb/LoginPage.aspx'>
用户名:<input name='UserID' type='text'>
密码:<input name='UserPwd' type='password'>
<input type='image' src='http://www.xxxx.com.cn/images/login.gif'>
</form>
</body>
</html>用类似以下的代码无法点击那个登录按钮(也就是 login.gif 图片按钮)
MSHTML::IHTMLElementCollection* pColl = NULL;
hr=spHtmlDocument->get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
{
MSHTML::IHTMLElement* pElem = NULL;
disp=pColl->item( name, index );
if(disp==NULL)
hr=E_FAIL;
else
{
hr=disp->QueryInterface(&pElem);
}......
}我觉得好像 item函数必须要指定 网页元素的"名称(name)"或者"索引号(index)"
但是在IE中这个网页却是可以点击提交的.请问如何用程序实现,点击这个 登录按钮呢?
一般都可以用document.forms[0].submit提交网页,除非网页上有多个表单,这时候需要用序号访问。以前我和111222讨论过一个分析HTML表格的问题的时候涉及到集合元素的访问的,你可以去全文搜索哪里找找"jiangsheng 111222"。本贴以现状提供并不带有任何担保,使用者需要考虑并承担可能的风险。
本贴只表示jiangsheng在发表当时的观点,不代表任何一个公司或者组织的意见
在米国用小猫真不习惯:(
Command what is yours Conquer what is not
我本来一味的想点击 submit按钮。
经过两位的指点,原来换一种方法去考虑更简单。
谢谢了,两位指点迷津。
送分!
以下是我实现的代码。
若有同样的疑问可以参考。///////////////////////////////////////////////////////////////////////////
// 提交网页中的Formvoid CTestDlg::SubmitForm(MSHTML::IHTMLDocument2Ptr spHtmlDocument, CString butName, const int &index)
{
HRESULT hr;
MSHTML::IHTMLElementCollection* pColl = NULL; hr=spHtmlDocument->get_forms(&pColl); if(pColl!=NULL&&SUCCEEDED(hr))
{
MSHTML::IHTMLFormElement* pElem = NULL;
_variant_t index_vt; // 网页中表单的序号
index_vt.vt=VT_I4;
if( index > -1 )
index_vt.intVal = index;
else
index_vt = vtMissing; _variant_t name; if( !butName.IsEmpty() )
{
_variant_t temp( butName );
name = temp;
}
else
name = vtMissing;
IDispatchPtr disp; disp=pColl->item( name, index_vt );
if(disp==NULL)
hr=E_FAIL;
else
{
hr=disp->QueryInterface(&pElem);
}
if (SUCCEEDED(hr)&& pElem != NULL)
{
pElem->submit();
pElem->Release();
}
pColl->Release();
}
}