Search code examples
c#xpathgeckofx

C# GeckoFX Browser - How to click/set value to XPath?


Im having problems with website automation, I am able to confirm if website contains XPath im looking for, but I have no idea how to make program to set text or click it.

Im using Firefox 22.0 / Xulrunner 22.0

Code I used to verify if website contains XPath:

GeckoNode element = gWB.Document.GetSingleElement(x.ToString());
if (element != null)
{
    //What here to make program to click/fill XPath?
}

Thanks


Solution

  • To perform a click, cast the GeckoNode type to GeckoHtmlElement then you can call the click method.

    GeckoHtmlElement element = (GeckoHtmlElement)gWB.Document.GetSingleElement(x.ToString());
    if (element != null)
    {
        element.Click();        
    }
    

    Setting the value can be different depending on the type of the element, but you can try and use attributes such as NodeValue, TextContent, and InnerHtml.