Create loops and parsing XML nodes value for Selenium tests



I am trying to write a test function in C# that read data from an XML file and parse into Selenium testing methods , the XML code is like:



<home>
<ask_frame>
<id>Object ID<id>
<xpath>Object XPath<xpath>
</ask_frame>
<search_frame>
<id>Object ID<id>
<xpath>Object XPath<xpath>
</search_frame>
<home>


I am trying to create a loop that read the id and xpath value from these nodes and parse them into an method for searching a webpage element by id and xpath. My initial attempt was:



XmlDocument xd = new XmlDocument();
xd.Load(@"C:\XMLFile1.xml");
XmlNodeList mainlist = xd.SelectNodes("home");
XmlNodeList idlist = xd.SelectNodes("id");
XmlNodeList xpathlist = xd.SelectNodes("XPath");
XmlNode mainroot = mainlist[0];
XmlNode idroot = idlist[0];
XmlNode pathroot = xpathlist[0];

foreach (XmlNode xnode in mainroot.ChildNodes)
{
string objID = idroot.InnerText;
string objXPath = pathroot.InnerText;
objectCheck(objID, objXPath);
}


However this is incorrect and throws an "Object reference not set to an instance of an object" error. I am still very new to C# , so any suggestions or hints for this problem will be highly appreciated.


No comments:

Post a Comment