I'm using webBrowser control in winform app C# FW4.0, and I would like to find all the elements that their class attribute contains some value. Is it possible?
Asked
Active
Viewed 1,830 times
0
-
Yes it is possible. any other question? – L.B Jun 19 '14 at 19:14
-
Question #2: How can it be done? – Itay.B Jun 19 '14 at 19:15
-
It is not a question. It is *write-it-for-me*. Post what you have tried and where you got stuck. – L.B Jun 19 '14 at 19:18
-
If you don't want to share your knowledge it's fine. Just say so. – Itay.B Jun 19 '14 at 19:19
-
What @L.B is looking for is what code have you tried and why isn't it working for you. Do you have a direct question about some documentation which may or may not be confusing to you? – TheNorthWes Jun 19 '14 at 19:19
-
@Itay.B No, you misunderstand me. I just don't want to do the work for who doesn't google and just tries to find someone to write it for him (don't take it personally). See my second comment and try to improve your question. – L.B Jun 19 '14 at 19:22
-
Do you really think I would ask you guys before googling? – Itay.B Jun 19 '14 at 19:23
-
@Itay.B then where did you get stuck? anything to show? Just take a step back and see your question. So poor with 1K reps. – L.B Jun 19 '14 at 19:24
-
I just find that there is a GetElementsByID function and another one ByTagName. Nothing like GetElementsByAttributeContent, which means I will have to loop on all 100's of elements on my document in order to find 1 or 2 of them. – Itay.B Jun 19 '14 at 19:26
-
@Itay.B I would use HtmlAgilityPack (with XPath support). Just search at this site. There are many answers... – L.B Jun 19 '14 at 19:38
-
@L.B Thank you very much. Looks good. Can you add it as an answer so I'll be able to mark it as correct answer? – Itay.B Jun 19 '14 at 19:44
1 Answers
1
You can do this, but it will take some work on your own.
An example on how to find all a
tags with class show1
should help you find what you need. Here is an excerpt from the example there
var links = webBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement link in links)
{
if (link.GetAttribute("class") == "show1")
{
//do something
}
}

Community
- 1
- 1

TheNorthWes
- 2,661
- 19
- 35