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

有帮助吗?

解决方案

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.

其他提示

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();
    //..
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top