문제

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