Unit Test to parse HTML in Windows Phone 8 Apps RRS feed

  • Question

  • Hello All,

    Is it possible to write Unit tests which can parse the HTML obtained from a website. Currently i am using the Visual Studio CTP2, Windows Phone 8 Unit Test App.

    I am trying something like this -

    WebBrowserTask task = new WebBrowserTask();

    task.Uri = new System.Uri("");


    This works fine, but i am not able to fetch the HTML from this site. 

    Also I tried this - 

    WebBrowser browser = new WebBrowser();

    browser.Navigate(new Uri("");

    When the navigate method is called, the Unit Test App stops running with no error.

    Any help much Appreciated!


    Monday, September 2, 2013 4:05 PM

All replies

  • the webBorwser/Task only opens up the web page if im correct. if you want to get the html from the webpage you have to make a request to the website and the response will be the html. I usually use HttpClient but you can use WebClient. so for example it would look like:

    public MainPage()
                // Sample code to localize the ApplicationBar
                WebClient client = new WebClient();
                client.DownloadStringCompleted += client_DownloadStringCompleted;
                client.DownloadStringAsync(new Uri("Http://"));
            void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    so make an instance of the webclient. set up the event handler. then call downloadstringAsync and pass in the web site you want to get. the debug.writeline is to just print it out in the ouput. I do that to see if I really captured the html

    Monday, September 2, 2013 4:34 PM
  • Hello Javier,

    What User Agent this method use ? I tried using this but the HTML which was downloaded was different then what is expected for Windows Phone 8 IE 10 Browser. Basically our site is on Adaptive rendering and hence the HTML changes as the device changes.

    Tuesday, September 3, 2013 8:41 AM
  • I'm not sure, but here's a link that may help that discusses how to set the user agent

    Tuesday, September 3, 2013 2:08 PM