[英]How to find and click links/buttons by href? (GeckoFx browser)
过去我使用
GeckoElementCollection elements = iframe.ContentDocument.GetElementsByName("name");
foreach (var element in elements)
{
if (element.GetAttribute("href") == "text")
{
MessageBox.Show(element.GetAttribute("class"));
}
}
所以我按名称查找元素,然后我检查了 href 是否我试图找到它的元素。 现在我没有任何元素名称只有类(类对于少数元素是相同的),唯一的是href。 所以我需要通过 href 搜索元素并用它执行点击/输入事件。
我相信我需要使用 GeckoNode
GeckoNode node = iframe.ContentDocument.GetElementsByClassName("classname")[0].FirstChild;
if (NodeType.Element == node.NodeType)
{
MessageBox.Show(node.GetAttribute("hreff"));
}
但是 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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.