N
nicolas
Hello,
Somebody knows how i can simulate a click on a <A HAREF> tag ?
THX
Nico
Somebody knows how i can simulate a click on a <A HAREF> tag ?
THX
Nico
nicolas said:Somebody knows how i can simulate a click on a <A HAREF> tag ?
Arne Janning said:nicolas said:Somebody knows how i can simulate a click on a <A HAREF> tag ?
Hi Nicolas,
//add a reference to the MSHTML Object Library
[...]
public Form1()
{
InitializeComponent();
// Wait until the document has finished loading
axWebBrowser1.DocumentComplete +=
new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(
axWebBrowser1_DocumentComplete);
}
private void button1_Click(object sender, System.EventArgs e)
{
//C# cannot deal with optional params
object miss = Type.Missing;
//goto google.com
axWebBrowser1.Navigate(
"http://www.google.com", ref miss, ref miss, ref miss, ref miss);
}
//is called when the browser has finished loading the page
private void axWebBrowser1_DocumentComplete(
object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
//get a reference to the HTML-document
mshtml.HTMLDocumentClass doc =
(mshtml.HTMLDocumentClass) axWebBrowser1.Document;
//foreach link in the HTML-document
foreach (mshtml.HTMLAnchorElementClass link in doc.links)
{
if (link.href == "http://www.google.de/grphp?hl=de&tab=wg")
{
//perform the click on the Google-Groups-Link
link.click();
}
}
}
Cheers
Arne Janning
nicolas said:thanks Arne, i will try it.
Arne Janning said:nicolas said:Somebody knows how i can simulate a click on a <A HAREF> tag ?
Hi Nicolas,
//add a reference to the MSHTML Object Library
[...]
public Form1()
{
InitializeComponent();
// Wait until the document has finished loading
axWebBrowser1.DocumentComplete +=
new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(
axWebBrowser1_DocumentComplete);
}
private void button1_Click(object sender, System.EventArgs e)
{
//C# cannot deal with optional params
object miss = Type.Missing;
//goto google.com
axWebBrowser1.Navigate(
"http://www.google.com", ref miss, ref miss, ref miss, ref miss);
}
//is called when the browser has finished loading the page
private void axWebBrowser1_DocumentComplete(
object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
//get a reference to the HTML-document
mshtml.HTMLDocumentClass doc =
(mshtml.HTMLDocumentClass) axWebBrowser1.Document;
//foreach link in the HTML-document
foreach (mshtml.HTMLAnchorElementClass link in doc.links)
{
if (link.href == "http://www.google.de/grphp?hl=de&tab=wg")
{
//perform the click on the Google-Groups-Link
link.click();
}
}
}
Cheers
Arne Janning
nico said:Sorry i have try it with yahoo.com and it does not work. I have an error
with "Le cast spécifié n'est pas valide" in french (the specify cast is
not valid). This error is with "mshtml.HTMLAnchorElementClass link in"
Arne Janning said:Hi Nico,
then try it with
foreach (mshtml.IHTMLElement he in doc.links)
{
HTMLAnchorElementClass hae = he as HTMLAnchorElementClass;
...
}
Cheers
Arne Janning
nicolas said:it does not work ... i have a System.NullReferenceException error.
hae is not defined value
nicolas said: