Frage

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

War es hilfreich?

Lösung

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.

Andere Tipps

If you want to use XPath, you can try with this:

browser.LoadXml("<MyTag><div>helloworld</div></MyTag>");

var r = browser.Document.EvaluateXPath("//div");
Assert.AreEqual(1, r.GetNodes().Count());

so in prev code:

GeckoElementCollection nodes = browser.Document.EvaluateXPath(x.ToString()).GetNodes();    
foreach(GeckoNode node in nodes)
{
    //do whatever you need to do with the node .. 
    GeckoElement element = node as GeckoElement;
    element.click();
    //..
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top