C# 如何通过href查找并单击链接/按钮?(壁虎浏览器)
过去我用的是C# 如何通过href查找并单击链接/按钮?(壁虎浏览器),c#,geckofx,C#,Geckofx,过去我用的是 GeckoElementCollection elements = iframe.ContentDocument.GetElementsByName("name"); foreach (var element in elements) { if (element.GetAttribute("href") == "text") {
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 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();
}
}