过去我使用
GeckoElementCollection elements = iframe.ContentDocument.GetElementsByName("name");
foreach (var element in elements)
{
if (element.GetAttribute("href") == "text")
{
MessageBox.Show(element.GetAttribute("class"));
}
}
Run Code Online (Sandbox Code Playgroud)
所以我按名称查找元素,然后我检查了 href 是否我试图找到它的元素。现在我没有任何元素名称只有类(类对于少数元素是相同的),唯一的是href。所以我需要通过 href 搜索元素并用它执行点击/输入事件。
我相信我需要使用 GeckoNode
GeckoNode node = iframe.ContentDocument.GetElementsByClassName("classname")[0].FirstChild;
if (NodeType.Element == node.NodeType)
{
MessageBox.Show(node.GetAttribute("hreff"));
}
Run Code Online (Sandbox Code Playgroud)
但是 GetAttribute 不适用于节点。有什么想法吗?
我知道这个问题很老,但今天我遇到了同样的问题,我解决了它。尝试这样的事情:
GeckoElementCollection fblikes = webBrowser.Document.GetElementsByTagName("a");
foreach (GeckoHtmlElement item in fblikes)
{
string aux = item.GetAttribute("href");
if (!string.IsNullOrWhiteSpace(aux) && aux.Equals("p.php?p=facebook"))
{
item.Click();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3607 次 |
| 最近记录: |