用c#浏览器点击链接
本文关键字:链接 浏览器 | 更新日期: 2023-09-27 18:18:50
底层代码,选择您想要的单词。我写了这些话,我想点击链接。单词可能是错误的,所以我使用谷歌翻译。只有"范围"值语句怎么点击?谢谢你。
if (webBrowser1.Document != null)
{
IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2;
if (document != null)
{
IHTMLSelectionObject currentSelection = document.selection;
IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;
if (range != null)
{
const String search = "Sayfalar";
if (range.findText(search, search.Length, 2))
{
range.select();
}
}
}
}
要提交表单,您只需要知道提交按钮的id
VB。净
For Each html As System.Windows.Forms.HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
If html.InnerText = "YOUR TEXT" Then
html.InvokeMember("click")
End If
Next
c# foreach (System.Windows.Forms.HtmlElement html in WebBrowser1.Document.GetElementsByTagName("a")) {
if (html.InnerText == "YOUR TEXT") {
html.InvokeMember("click");
}
}
如有疑问请联系。
我不知道你在问什么。你是在要求使用c#实现浏览器自动化吗?
下面是使用MSHTML: 单击的示例using mshtml;
var element = webBrowser1.Document.GetElementById("q");
((IHTMLElement)element.DomElement).click();
p。Alexander Kent写了一篇很棒的关于使用c#实现浏览器自动化的文章