SimpleBrowserDotNet / SimpleBrowser.WebDriver

A webdriver for SimpleBrowser
Apache License 2.0
43 stars 16 forks source link

iframes with href="javascript:" throw an invalid Uri Exceptions #9

Closed yetanotherchris closed 12 years ago

yetanotherchris commented 12 years ago

If an iframe (or possibly other links) have href="javascript:", SimpleBrowser throws an exception.

Weirdly, new Uri("javascript:") is valid, but creating the web request fails.

Teun commented 12 years ago

Hi Chris,

I've been trying to reproduce your issue, but unsuccessfully. Can you have a look at this test code and see where I did not understand your issue?

    [Test]
    public void FrameMayHaveInvalidUrls_Issue9()
    {
        IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker(
            new List<Tuple<string, string>>()
            {
                Tuple.Create("^/frame", @"<html><a href=""javascript:"">link</a></html>"),
                Tuple.Create("^.*", @"
                                    <html>
                                        <iframe src=""/frame""/><iframe name=""inv"" src=""javascript:""/>
                                    </html>"),
            }
            )));
        var dr = new SimpleBrowserDriver((IBrowser)b);
        b.Navigate("http://blah/");
        foreach (var item in b.Frames)
        {
            Console.WriteLine(item.Url);
            Console.WriteLine(item.CurrentHtml);
        }
        //when clicking a javascript: URL it throws an exception. It this your problem?
        Assert.Throws<UriFormatException>(() => { b.Frames.First().Select("a").Click(); });
    }
yetanotherchris commented 12 years ago

The website I was using was totaljobs.com - that uses javascript:''

It'd be handy if there was an option to just ignore iframes.

Teun commented 12 years ago

I can load it without problem using

        var b1 = new SimpleBrowserDriver();
        b1.Navigate().GoToUrl("http://www.totaljobs.com/");

Can you give me some failing sample code?

yetanotherchris commented 12 years ago

This snippet is what's triggering it:

SimpleBrowserDriver driver = new SimpleBrowserDriver(); driver.Navigate().GoToUrl("http://www.totaljobs.com"); driver.FindElement(By.Id("top_0_txtKeywords")).SendKeys("accountant"); driver.FindElement(By.Id("top_0_btnSearch")).Click();

Console.Read();

On Sun, Oct 7, 2012 at 7:44 PM, Teun notifications@github.com wrote:

I can load it without problem using var b1 = new SimpleBrowserDriver(); b1.Navigate().GoToUrl("http://www.totaljobs.com/");

Can you give me some failing sample code?

— Reply to this email directly or view it on GitHubhttps://github.com/Teun/SimpleBrowser.WebDriver/issues/9#issuecomment-9210880.

Teun commented 12 years ago

I've just pushed a version of SimpleBrowser and SimpleBrowser.WebDriver that should fix this problem. Thanks for reporting. I hope this fixes your issue.