0

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);
        }

    }
User1003
  • 1
  • 4
  • 2
    Always post the code itself if possible, instead of images. – Jim Nov 14 '16 at 16:37
  • 1
    Possible duplicate of [How do I read and parse an XML file in C#?](http://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c) – lauda Nov 14 '16 at 17:10
  • 1
    Please see http://stackoverflow.com/questions/642293/how-do-i-read-and-parse-an-xml-file-in-c and do another search, you will find a lot of questions with sample code. – lauda Nov 14 '16 at 17:11

0 Answers0