I'm using a webbrowser control on my form program and showing a web page in it. I want to find the tag below;
<a href="index.jsp">Succesfully Posteda>
When a page has this code, i want to write "ok" on a textbox in form. I tryed the codes below but it isnt exactly work. How can i do that?
foreach (HtmlElement HtmlElement1 in webBrowser1.Document.Body.All)
{
if (HtmlElement1.Document.GetElementById("a").GetAttribute("href") == "index.jsp")
{
textBox6.Text = "Ok";
}
}
Roei BarPosted Sep 20, 2009, 12:23 PM
yokzuPosted Sep 23, 2009, 2:26 PM
yokzuPosted Sep 21, 2009, 6:10 PM
Firstly roei, i am using WebBrowserDocumentCompletedEventArgs function. when i am loading the first html page, the codes are working correctly. But when i click a button and visiting another html page, the codes are not working properly. I mean i arrange my codes for finding tag on second page (after clicking) but i couldnt find tags correctly on second page. My all codes are below. Are there any problem?
private void page_success(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Body.SetAttribute("background", "#000000");
webBrowser1.Document.Body.Style = "background:#7fffd4";
foreach (HtmlElement htmlEl in webBrowser1.Document.Body.GetElementsByTagName("a"))
{
if (htmlEl.GetAttribute("href") == "index.jsp")
{
textBox6.Text = "OK";
}
}
}
Dushan StankovicPosted Sep 21, 2009, 2:20 AM
Roei BarPosted Sep 20, 2009, 2:40 PM
about the answer above this one, it will work but might jump the msgbox more then once :-)
Dushan StankovicPosted Sep 20, 2009, 1:18 PM
foreach (HtmlElement htmlEl in webBrowser1.Document.Body.GetElementsByTagName("a"))
{
if (htmlEl.GetAttribute("href") == "index.jsp")
textBox1.Text = "OK";
}
yokzuPosted Sep 20, 2009, 1:13 PM
But when i try you code like below, its getting that error "The type or namespace name 'HTMLDocument' could not be found (are you missing a using directive or an assembly reference?)"
I added the namespaces below;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
I am using " private void page_success(object sender, WebBrowserDocumentCompletedEventArgs e)" function. It can be a problem?