I'm using a webbrowser control on my form program and showing a web page in it. I want to find the tag below;
C#
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 BarRank #1,271 · 1.4K reputationPosted Sep 20, 2009, 8:23 AM EDT
# HTMLDocument objHtmlDoc = (HTMLDocument) webBrowser1.Document.DomDocument; # /*webBrowser1 is the WebBrowser Control showing your page*/ # string pageSource = objHtmlDoc.documentElement.innerHTML; //then if (pageSource.Contains(@"a href="index.jsp">Succesfully Posteda>") textBox6.Text = "Ok";yokzuRank #5,421 · 300 reputationPosted Sep 20, 2009, 9:13 AM EDT
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?
Dushan Stankovic72 reputationPosted Sep 20, 2009, 9:18 AM EDT
foreach (HtmlElement htmlEl in webBrowser1.Document.Body.GetElementsByTagName("a"))
{
if (htmlEl.GetAttribute("href") == "index.jsp")
textBox1.Text = "OK";
}
Roei BarRank #1,271 · 1.4K reputationPosted Sep 20, 2009, 10:40 AM EDT
about the answer above this one, it will work but might jump the msgbox more then once :-)
Dushan Stankovic72 reputationPosted Sep 20, 2009, 10:20 PM EDT
yokzuRank #5,421 · 300 reputationPosted Sep 21, 2009, 2:10 PM EDT
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";
}
}
}
yokzuRank #5,421 · 300 reputationPosted Sep 23, 2009, 10:26 AM EDT