VB.Net - 使用GetElementByClass选择一个类,然后以编程方式单击该项目 [英] VB.Net - select a class using GetElementByClass and then click the item programmatically

查看:143
本文介绍了VB.Net - 使用GetElementByClass选择一个类,然后以编程方式单击该项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在在发布这个问题之前,我确实阅读了......



如何通过GetElementByClass选择一个类,并通过编程方式点击它
<但这不适合我。显然我是一个白痴,不知道如何使用该代码,或者它只是不适合我。我也在VB.NET中使用WebBrowser控件,如果这有帮助的话......



我有以下我试图点击...

 < div class =closewindow>< / div> 

现在当然是埋在吨和其他股票的下面和里面,但它不会有任何直接的所有者。没有或者类似的东西。它只是坐在自己身边



这里是它的拦截的HTML

 < div class =main_class> 
< div id =FullItemView>
< div style =width:90%; float:left;>
< div class =headline>
< table style =width:100%;>
< tbody>< tr>
< td style =width:15%; text-align:right; vertical-align:middle;>
< img class =switchImagesrc =pictures / pic.png>< / td>
< td style =width:70%; vertical-align:middle;>
< span class =ListItemTitle>叛徒< / span>< / td>
< td style =width:15%; text-align:left;>
< img class =switchImagesrc =pictures / pic.png>< / td> < / TR> < / tbody的>< /表>
< / div>
< / div>
< div class =closeWindow>< / div>
......

现在我只希望能够选出然后在这个div和这个div上调用click。我知道当它被点击时,是因为服务器上有一些PHP代码,但这需要很长时间才能解释它是如何工作的。



任何人都知道我可以单身所以当我有一个变量XITEM或.NET内的东西,然后我可以调用它?如果我有......

 对于WebBrowser1.Document.GetElementsByTagName(div)中的HTMLELEMENT XITEM 
......
item.invokeMember(click)
.....

然后它只点击HTMLELEMENT选中。希望这对每个人都有用解决方案

/ p>

  Dim theElementCollection As HtmlElementCollection = Nothing 
theElementCollection = WebBrowser1.Document.GetElementsByTagName(div)
For每个curElement As HtmlElement在ElementEollection中
'如果curElement.GetAttribute(classname)。ToString =example它不起作用。
'这应该是周围的工作。
如果InStr(curElement.GetAttribute(classname).toString,closeWindow)然后
'甚至不会触发。
'找到课后的InvokeMember(test)。
'MessageBox.Show(curElement.GetAttribute(InnerText))
curElement.InvokeMember(Click)
curElement.InvokeMember(MouseDown)
curElement.InvokeMember MouseUp)
curElement.RaiseEvent(OnClick)
curElement.Focus()
End If
Next


Now before posting this question i did read...

How to select a class by GetElementByClass and click on it programmically

But this doesn't work for me. Apparently I'm an idiot and don't know how to use that code, or its just not working for me. I also am using the WebBrowser Control in VB.NET if that helps at all...

I have the following I'm trying to click...

<div class="closewindow"></div>

Now of course this is buried below and inside tons and tons of other divs, but it doesn't have any direct "owner". There is no or anything like that. Its just sitting by itself

Here is the html its barried in

<div class="main_class">  
<div id="FullItemView">  
<div style="width: 90%; float: left;">  
<div class="headline">  
<table style="width: 100%;">    
<tbody><tr>      
<td style="width: 15%; text-align: right; vertical-align: middle;">
<img class="switchImage" src="pictures/pic.png"></td>      
<td style="width: 70%; vertical-align: middle;">
<span class="ListItemTitle">Renegade</span></td>      
<td style="width: 15%; text-align: left;">
<img class="switchImage" src="pictures/pic.png"></td>    </tr>  </tbody></table>  
</div>  
</div>  
<div class="closeWindow"></div>
......

Now I just want to be able to single out the and then invoke a "click" on this div and this div only. I know when its being clicked because of some PHP code thats on the server, but that would take too long to explain how that works.

Anyone know how i can single this out so when i have a variable XITEM or something inside .NET then i can invoke it? Like if I had ...

For XITEM as HTMLELEMENT in WebBrowser1.Document.GetElementsByTagName("div")
......
item.invokeMember("click")
.....

Then it clicks only the HTMLELEMENT "chosen". Hopefully this makes sense to everyone

解决方案

I figured it out after messin around with the original post that I found on stackoverflow.com

Dim theElementCollection As HtmlElementCollection = Nothing
        theElementCollection = WebBrowser1.Document.GetElementsByTagName("div")
        For Each curElement As HtmlElement In theElementCollection
            'If curElement.GetAttribute("classname").ToString = "example"  It doesn't work.  
            ' This should be the work around.
            If InStr(curElement.GetAttribute("classname").ToString, "closeWindow") Then
                ' Doesn't even fire.
                ' InvokeMember(test) after class is found.
                'MessageBox.Show(curElement.GetAttribute("InnerText"))
                curElement.InvokeMember("Click")
                curElement.InvokeMember("MouseDown")
                curElement.InvokeMember("MouseUp")
                curElement.RaiseEvent("OnClick")
                curElement.Focus()
            End If
        Next

这篇关于VB.Net - 使用GetElementByClass选择一个类,然后以编程方式单击该项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆