【发布时间】:2019-06-09 08:48:14
【问题描述】:
我正在为一家需要自动化 twitter like 按钮的公司开发 twitter 管理工具。
事实证明,我无法以任何方式自动点击。
有人对我如何做到这一点有任何建议吗?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
ListBox1.Items.Add(webpageelement.GetAttribute("class"))
If webpageelement.GetAttribute("class") = "css-1dbjc4n r-sdzlij r-1p0dtai r-xoduu5 r-1d2f490 r-xf4iuw r-u8s1d r-zchlnj r-ipm5af r-o7ynqc r-6416eg" Then
webpageelement.InvokeMember("click")
End If
Next
End Sub
【问题讨论】:
-
属性是
className(完全像这样写),而不是class(你不会找到任何与这个属性匹配的元素)。您还应该让浏览器处理底层脚本,启用 IE11/Edge 兼容模式。请参阅:How can I get the WebBrowser control to show modern contents?。