我正在尝试点击网站上的href链接,这会引导我访问网站的另一个页面,这是我的代码:
private const string baseURL = "https://abv.bg/";
public Form1()
{
InitializeComponent();
localWebBrowser.DocumentCompleted += WebBrowser_DocumentCompleted;
localWebBrowser.Navigate(baseURL);
}
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
MessageBox.Show(localWebBrowser.Url.ToString());
HtmlElement lostPasswordButton = ObtainHtmlElementById(localWebBrowser, "lostPasswordLink");
if (lostPasswordButton == null)
{
throw new InvalidOperationException($"Couldn't find {nameof(lostPasswordButton)}");
}
lostPasswordButton.InvokeMember("click");
}
private HtmlElement ObtainHtmlElementById(WebBrowser webBrowser, string elementName)
{
return webBrowser.Document.GetElementById(elementName);
}
这是按钮的html:
这是我得到的错误: