通过 table 网络浏览器中的 html 字符串查找并单击单元格
Find and Click cell by inner html string inside table Webbrowser
我试图在第 1 列中查找字符串并自动单击第 3 列中的 "detail"..
|-----------------------------------------|
| Column 1 | Column 2 | Column 3 |
|-----------------------------------------|
| David | 12345 | detail |
| Jhon | 67890 | detail |
| Ester | 67890 | detail |
直到最近,我只能使用以下代码找到第 1 列中的单词:
Dim tables As HtmlElementCollection = Me.WebBrowser.Document.GetElementsByTagName("table")
For Each tbl As HtmlElement In tables
For Each row As HtmlElement In tbl.All
For Each cell As HtmlElement In row.All
If Not cell.Style Is Nothing Then
If cell.InnerText.Contains("Jhon") Then
cell.InvokeMember("click") '---Not working because "Jhon" is not Hyperlink.
End If
End If
Next
Next
Next
现在我必须想办法点击第 3 列中的“详细信息”一词。这可能吗?
找到要查找的单元格后,只需迭代该行中的其余单元格,直到找到 "detail" 单元格。
If cell.InnerText.Contains("Jhon") Then
For Each rcell As HtmlElement In row.All
If rcell.InnerHtml.Contains("detail") Then
rcell.InvokeMember("click")
Exit For
End If
Next
End If
或者,如果单击单元格本身不起作用,请单击第一个 a
标记:
If cell.InnerText.Contains("Jhon") Then
For Each rcell As HtmlElement In row.All
If rcell.InnerHtml.Contains("detail") Then
Dim tags As HtmlElementCollection = rcell.GetElementsByTagName("a")
If tags.Length > 0 Then
tags(0).InvokeMember("click")
End If
Exit For
End If
Next
End If
我试图在第 1 列中查找字符串并自动单击第 3 列中的 "detail"..
|-----------------------------------------|
| Column 1 | Column 2 | Column 3 |
|-----------------------------------------|
| David | 12345 | detail |
| Jhon | 67890 | detail |
| Ester | 67890 | detail |
直到最近,我只能使用以下代码找到第 1 列中的单词:
Dim tables As HtmlElementCollection = Me.WebBrowser.Document.GetElementsByTagName("table")
For Each tbl As HtmlElement In tables
For Each row As HtmlElement In tbl.All
For Each cell As HtmlElement In row.All
If Not cell.Style Is Nothing Then
If cell.InnerText.Contains("Jhon") Then
cell.InvokeMember("click") '---Not working because "Jhon" is not Hyperlink.
End If
End If
Next
Next
Next
现在我必须想办法点击第 3 列中的“详细信息”一词。这可能吗?
找到要查找的单元格后,只需迭代该行中的其余单元格,直到找到 "detail" 单元格。
If cell.InnerText.Contains("Jhon") Then
For Each rcell As HtmlElement In row.All
If rcell.InnerHtml.Contains("detail") Then
rcell.InvokeMember("click")
Exit For
End If
Next
End If
或者,如果单击单元格本身不起作用,请单击第一个 a
标记:
If cell.InnerText.Contains("Jhon") Then
For Each rcell As HtmlElement In row.All
If rcell.InnerHtml.Contains("detail") Then
Dim tags As HtmlElementCollection = rcell.GetElementsByTagName("a")
If tags.Length > 0 Then
tags(0).InvokeMember("click")
End If
Exit For
End If
Next
End If