我正在使用GeckoWebBrowser处理Windows应用程序,并试图通过代码检查Captcha的复选框。 Programmaticaly我已经可以获取和设置html元素,但这个复选框我无法覆盖。我无法在页面的任何位置找到它。 我不是想要确定或解决验证码,只需选中复选框元素,然后验证它是否被选中。那样简单。GeckoWebBrowser如何标记Captcha复选框(C#Windows窗体)?
我知道此刻是什么:
在Firefox的检查,我可以看到 一些明显的信息:验证码与标题=“窗口小部件的reCAPTCHA”一个IFRAME,宽度= 304和高度= 78 。
现在,这是我怎么想获取的复选框,寻找ID,跨度,DIV和阶级与不同的方式没有成功...
首先,在主文档
//looking all elements into main Document (around 1300 elements)
GeckoElementCollection collection = geckoWebBrowser1.Document.GetElementsByTagName("*");
foreach (GeckoHtmlElement elem in collection)
{
string id = elem.Id;
if (id == "recaptcha-anchor")
{
string myId = "this is my ID"; //never find this ID!
}
//just for debug
string LocalName = elem.LocalName;
string OuterHtml = elem.OuterHtml;
string TagName = elem.TagName;
string TextContent = elem.TextContent;
string role = elem.GetAttribute("role");
string value = elem.GetAttribute("value");
}
所以,在主文档,我不能找到任何ID。
下,寻找到IFRAME:
//get the iframe works well
foreach (GeckoIFrameElement iframe in geckoWebBrowser1.Document.GetElementsByTagName("iframe"))
{
//get main info about the iframe - ok
string title = iframe.GetAttribute("title");
if (title != null && title.ToLower().Contains("captcha")) //got "recaptcha widget"
{
int x = iframe.OffsetLeft;
int y = iframe.OffsetTop;
int width = Convert.ToInt32(iframe.Width);
int height = Convert.ToInt32(iframe.Height);
}
//inside the iframe, get all elements --> but always return null
Gecko.Collections.IDomHtmlCollection<GeckoElement> collection2 = iframe.GetElementsByTagName("*");
foreach (GeckoHtmlElement elem in collection2)
{
string id = elem.Id;
string LocalName = elem.LocalName;
string OuterHtml = elem.OuterHtml;
string TagName = elem.TagName;
string TextContent = elem.TextContent;
string role = elem.GetAttribute("role");
string value = elem.GetAttribute("value");
}
//foreach (GeckoHtmlElement elem in iframe.GetElementsByTagName("*")) //get no elements
//foreach (GeckoHtmlElement elem in iframe.GetElementsByTagName("input")) //get no elements
//foreach (GeckoHtmlElement elem in iframe.GetElementsByTagName("div")) //get no elements
foreach (GeckoHtmlElement elem in iframe.GetElementsByTagName("span")) //get no elements
{
string id = elem.Id;
string LocalName = elem.LocalName;
string OuterHtml = elem.OuterHtml;
string TagName = elem.TagName;
string TextContent = elem.TextContent;
string role = elem.GetAttribute("role");
}
}
所以,很多的尝试和错误后,我无法获得该复选框元素,但我可以获取验证码框的一些信息,比如位置和大小,尽管标题并不像我预期的那样是100%:在Firefox中标题=“widget recaptcha”,在GeckoWebbrowser标题=“recaptcha widget”中......一个诡异的怪诞。
这是推动我疯了...... :-(
任何人有一些sugestion什么,我丢失或我在做什么错? 有一种方式来获得,甚至iframe中所有的HTML元素或完整元素树?
可以做什么,我想干什么?事先
谢谢!
我使用GeckoHtmlElement相反GeckoDivElement。谢谢! –