Webbrowser - simulate user actions on website-controls via QueryInterface
-
Hi, I've got one question using the WebBrowserControl. In my app a self refreshing website http://www.forexpf.ru/quote_show.php[^] is loaded in a webbrowser-control. The text content of the site is captured by QueryInterface() into a String to parse some data. This works fine, but ... On the website there is a list box and an button at the bottom, from which you can choose the interval for automatic refreshing the site. On initial loading 1min is chosen, but I want to change this to the shortest value (30sec). All the stuff is hidden, so the input should come from code (maybe via QueryInterface?). Are there any ideas to grab the list-control and the button and change the value? Here are the sample code for grabbing the content: - simple MFC-Dialog - one Webbrowser control (m_WebBrowserCtrl) - website is loaded and refreshed by button click - by clicking on a button the content of the site (plain text, not the html source) is copied into a CString variable to parse the data.
void CWebbrowser_TestDlg::OnCopy() { IHTMLDocument2* m_pHTMLDocument2; LPDISPATCH lpDispatch; lpDispatch = m_WebBrowserCtrl.GetDocument(); HRESULT hr; if (lpDispatch) { hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&m_pHTMLDocument2); lpDispatch->Release(); ASSERT(SUCCEEDED(hr)); } CString sText; IHTMLElement *iSource; BSTR bstrSource; m_pHTMLDocument2->get_body(&iSource); iSource->get_outerText(&bstrSource); sText = bstrSource; MessageBox(sText); }
TIA and greets M. -
Hi, I've got one question using the WebBrowserControl. In my app a self refreshing website http://www.forexpf.ru/quote_show.php[^] is loaded in a webbrowser-control. The text content of the site is captured by QueryInterface() into a String to parse some data. This works fine, but ... On the website there is a list box and an button at the bottom, from which you can choose the interval for automatic refreshing the site. On initial loading 1min is chosen, but I want to change this to the shortest value (30sec). All the stuff is hidden, so the input should come from code (maybe via QueryInterface?). Are there any ideas to grab the list-control and the button and change the value? Here are the sample code for grabbing the content: - simple MFC-Dialog - one Webbrowser control (m_WebBrowserCtrl) - website is loaded and refreshed by button click - by clicking on a button the content of the site (plain text, not the html source) is copied into a CString variable to parse the data.
void CWebbrowser_TestDlg::OnCopy() { IHTMLDocument2* m_pHTMLDocument2; LPDISPATCH lpDispatch; lpDispatch = m_WebBrowserCtrl.GetDocument(); HRESULT hr; if (lpDispatch) { hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&m_pHTMLDocument2); lpDispatch->Release(); ASSERT(SUCCEEDED(hr)); } CString sText; IHTMLElement *iSource; BSTR bstrSource; m_pHTMLDocument2->get_body(&iSource); iSource->get_outerText(&bstrSource); sText = bstrSource; MessageBox(sText); }
TIA and greets M.Hi, I guess you need to get the element of button and select box Give an id to the element in the web page get the document 3 interface
m_pHTMLDocument2->QueryInterface<IHTMLDocument3>(&spHTMLDocument3);
spHTMLDocument3->getElementById(spbstrID/*your id*/, &spHtmlElm);/* you can also use getElementsByName if you know the element name */
spHtmlElm->QueryInterface<IHTMLButtonElement>(&spBtnElm);
if (spBtnElm)
{
/* if the element was a button element set the required value */
spBtnElm->put_value(spBSTRValue);
}For list element you need to create option element to add an list item. Best Regards Raj