namespace WebCap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Skybound.Gecko.Xpcom.Initialize(@"C:\Program Files\xulrunner");
}
private void button1_Click(object sender, EventArgs e)
{
geckoWebBrowser1.Navigate(addtxbox.Text);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void geckoWebBrowser1_Navigating(object sender, Skybound.Gecko.GeckoNavigatingEventArgs e)
{
addtxbox.Text = geckoWebBrowser1.Url.ToString();
}
private void geckoWebBrowser1_DocumentCompleted(object sender, EventArgs e)
{
if ((geckoWebBrowser1.Url.ToString() == "http://kolotibablo.com/bablo.php?action=workInterface"))
{
HtmlElement elem = geckoWebBrowser1.Document.GetElementById("mainCaptchaImg");
string src = elem.GetAttribute("src");
this.ptcapget.ImageLocation = src;
}
}
}
}
我使用Skybound GeckoFX在C#中制作webbrowser,但我无法使用
HtmlElement elem = geckoWebBrowser1.Document.GetElementById("mainCaptchaImg")
显示此错误错误:
'无法将类型'Skybound.Gecko.GeckoElement'隐式转换为'System.Windows.Forms.HtmlElement'
答案 0 :(得分:1)
GetElementById
方法返回GeckoElement
,不 a HtmlElement
。
就像您无法将string
存储为int
一样,您无法将GeckoElement
存储为HtmlElement
,而这正是您要在此处执行的操作。
修改你的本地变量类型,一切都应该很好:
GeckoElement elem = geckoWebBrowser1.Document.GetElementById("mainCaptchaImg")