WatiN - Failure: System.UriFormatException : Invalid URI: The hostname could not be parsed

StackOverflow https://stackoverflow.com/questions/8496095

  •  15-03-2021
  •  | 
  •  

Question

Ok so I have been experimenting with Unit Testing. I am using Nunit and WatiN to do my testing and decided to try to implement the WatiN Test Recorder. I don't know if anyone is familiar with it, but I am using the 2.0 build (beta) I have the following code pulled direcltly from the test recorder and only slightly cleaned up.

 [TestFixture, RequiresSTA]
class WatiNTesting
{
    [Test]
    public void WatiNTest()
    {
        IE window = new IE("http://www.google.com");
        TextField txt_q = window.TextField(Find.ByName("q"));
        Element Locate = window.Element(Find.ByText("") && Find.ByValue("") && Find.ById("") && Find.BySrc("") && Find.ByUrl(""));
        Link lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510 = window.Link(Find.ByUrl("http://www.vietnamesetestingboard.org/zbxe/?mid=download&category=197510"));

        txt_q.TypeText("Watin");
        Locate.Click();
        lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510.Click();
        window.Dispose();            
    }
}

Whenever I go to run it, the window opens to goolge then Nununit returns this error:

Failure: System.UriFormatException : Invalid URI: The hostname could not be parsed.

Does anyone know how to get rid of this error, or a way to get around it?

Was it helpful?

Solution

Ok, the first problem seems to be with the Find.ByUrl call on this line...

Element Locate = window.Element(Find.ByText("") && Find.ByValue("") && 
    Find.ById("") && Find.BySrc("") && Find.ByUrl(""));

Remove it...

Element Locate = window.Element(Find.ByText("") && Find.ByValue("") &&
    Find.ById("") && Find.BySrc(""));

And it passes. Not really sure what you're trying to accomplish here, but hope this helps.

OTHER TIPS

Have you tried locating something like this:

Link link = window.Link(Find.By("rawurl", "http://www.vietnamesetestingboard.org/zbxe/?mid=download&category=197510"));

This might be occurring due to the presence of the ? character in your URL and the way WatiN internally operates while performing a find operation

You might want to try this

Link lnk_wwwvietnamesetestingboardorgzbxemiddownloadcategory197510 = window.Link(Find.ByUrl(new Regex(@"^http://www.vietnamesetestingboard.org/zbxe/\?mid=download&category=197510$")));

This uses a Regex overload for finding the URL and will escape the ? character.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top