How to click a link using Webkit browser?

I want to click the link after going to the website

 webKitBrowser1.Navigate("http://www.somesite.com");

How to click a link on this website, assuming the link identifier lnkId?

<a href="http://www.google.com" id="lnkId"> Go to Google </a>

In the default browser that comes with Visual Studio, I can do this using the following code:

 foreach (HtmlElement el in webBrowser1.Document.GetElementTagName("a")) {
 if (el.GetAttribute("id") == "lnkId") {
 el.InvokeMember("click");
 }
 }

What is the code equivalent above when I use the WebkitDotNet control?

+5
source share
3 answers

Since it WebKitdoes not provide an event Click()( see here for details ), you cannot do this above. But a little trick can work as the equivalent of the original winformsmethod, as shown below:

foreach (Node el in webKitBrowser1.Document.GetElementsByTagName("a"))
{
    if (((Element) el).GetAttribute("id") == "lnkId")
    {
        string urlString = ((Element) el).Attributes["href"].NodeValue;
        webKitBrowser1.Navigate(urlString);
    }
}

, , WebKit.DOM.Node WebKit.DOM.Element, Attributes. , href NamedNodeMap, .. Attributes NodeName, NodeValue, target url . Navigate(urlString) WebKitBrowser click.

+5

Windows, Webkit GTK. .

, webkit.NET . , . , , Wasif, javascript, https://code.google.com/p/open-webkit-sharp/source/browse/JavaScriptExample/Form1.cs.

, javascript, , DOM. API , javascript, , . javascript , , . , . , https://github.com/nhrdl/notesMD, , GTK .

, , Document.GetElementById .

+1
webKitBrowser1.StringByEvaluatingJavaScriptFromString("var inpt = document.createElement(\"input\");    inpt.setAttribute(\"type\", \"submit\");    inpt.setAttribute(\"id\", \"nut\"); inpt.setAttribute(\"type\", \"submit\");    inpt.setAttribute(\"name\", \"tmp\");   inpt.setAttribute(\"value\", \"tmp\");  var element = document.getElementById(\"lnk\"); element.appendChild(inpt);");
                    webKitBrowser1.StringByEvaluatingJavaScriptFromString("document.getElementById('nut').click();");
-1

All Articles