I am new to Selenium and sorry if this question was asked before. I created Object Repository using XML to keep all page elements in one place. I was trying to read/call data from XML file in my test scripts but could not figure it out. Can anybody advise me regarding that?
Thanks
<?xml version="1.0" encoding="utf-8"?>
<ObjRep>
<url>http://www.yahoo.com</url>
</ObjRep>
namespace ConsoleApplication2
class Program
{
static string url = "";
static string type = "";
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader("XMLFile1.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
if (reader.Name == "url")
type = "url";
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine(reader.Value);
if(type == "url")
url = reader.Value;
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
Console.ReadLine();
StartBrowser();
}
public static void StartBrowser()
{
IWebDriver d = new ChromeDriver();
d.Navigate().GoToUrl(url);
}
}