如何通过GetElementByClass选择一个类,点击它programmically

编程入门 行业动态 更新时间:2024-10-18 16:48:11
本文介绍了如何通过GetElementByClass选择一个类,点击它programmically的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在尝试使用此code阅读HTML / AJAX知道GetElementByClass由类元素不在webBrowser.Document一个选项。我似乎无法得到一个返回值,然后调用成员。是否有变通方法吗?

参考: 获取HTML元素由类名

例如:

<跨度类=榜样>(< A HREF =htt​​p://www.test/folder/remote/api?=test的onclick = 返回do_ajax('popup_fodder,远程/ API =测试?',1,1,0,0);返回false;阶级=榜样>测试< / A>)< / SPAN>

例如code:

HtmlElementCollection theElementCollection =默认(HtmlElementCollection);    theElementCollection = webBrowser1.Document.GetElementsByTagName(跨越);    的foreach(的HtmlElement curElement在theElementCollection)    {         //如果curElement.GetAttribute(类)。的ToString =榜样这是行不通的。         //这应该是周围的工作。         如果(curElement.OuterHtml.Contains(榜样))         {             的MessageBox.show(curElement.GetAttribute(的InnerText)); //甚至不火。             // InvokeMember(测试)课后发现。         }     }

解决方案

我承认它不是很直观,但你需要使用的getAttribute(类名),而不是的getAttribute(类)

HtmlElementCollection theElementCollection =默认(HtmlElementCollection);    theElementCollection = webBrowser1.Document.GetElementsByTagName(跨越);    的foreach(的HtmlElement curElement在theElementCollection)    {         //如果curElement.GetAttribute(类名)。的ToString =榜样这是行不通的。         //这应该是周围的工作。         如果(curElement.GetAttribute(类名)。的ToString =榜样)         {             的MessageBox.show(curElement.GetAttribute(的InnerText)); //甚至不火。             // InvokeMember(测试)课后发现。         }     }

I have been trying to use this code to read the element by class in html/ajax knowing GetElementByClass is not a option in webBrowser.Document. I can't seem to get a return value then invoke the member. Is there a work around for this?

References: Getting HTMLElements by Class Name

Example:

<span class="example">(<a href="www.test/folder/remote/api?=test" onclick=" return do_ajax('popup_fodder', 'remote/api?=test', 1, 1, 0, 0); return false; " class="example">test</a>)</span>

Example code:

HtmlElementCollection theElementCollection = default(HtmlElementCollection); theElementCollection = webBrowser1.Document.GetElementsByTagName("span"); foreach (HtmlElement curElement in theElementCollection) { //If curElement.GetAttribute("class").ToString = "example" It doesn't work. // This should be the work around. if (curElement.OuterHtml.Contains("example")) { MessageBox.Show(curElement.GetAttribute("InnerText")); // Doesn't even fire. // InvokeMember(test) after class is found. } }

解决方案

I admit it's not very intuitive but you need to use GetAttribute("classname") instead of GetAttribute("class")

HtmlElementCollection theElementCollection = default(HtmlElementCollection); theElementCollection = webBrowser1.Document.GetElementsByTagName("span"); foreach (HtmlElement curElement in theElementCollection) { //If curElement.GetAttribute("classname").ToString = "example" It doesn't work. // This should be the work around. if (curElement.GetAttribute("classname").ToString = "example") { MessageBox.Show(curElement.GetAttribute("InnerText")); // Doesn't even fire. // InvokeMember(test) after class is found. } }

更多推荐

如何通过GetElementByClass选择一个类,点击它programmically

本文发布于:2023-11-24 20:51:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626771.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:GetElementByClass   programmically

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!