Watin: BrowserNotFoundException on Browser.Attach<IE>(Find.ByURL(uri));

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mervin
    New Member
    • Oct 2012
    • 1

    Watin: BrowserNotFoundException on Browser.Attach<IE>(Find.ByURL(uri));

    Hello. I'm trying to find opened webpage by URI and to launch JS on it. I found some samples and wrote simple method. That's how it look:
    Code:
    private void GetHtmlCode()
    {
        string uri = GetTargetURI();
        if(!string.IsNullOrEmpty(uri))
        {
            IE ie = IE.AttachTo<IE>(Find.ByUrl(uri));
            htmlCode = ie.Eval(JavaScriptToRun);
        }
        else
        {
            MessageBox.Show("Target page is not opened",
                            "Notification", MessageBoxButtons.OK);
        }
    }
    And there's a method for getting URI:
    Code:
    private string GetTargetURI() //проверка URL
    {
        Regex reg;
        Match match;
        foreach(SHDocVw.InternetExplorer ie in shellWindows)
        {
            reg = new Regex(patternURL);
            match = reg.Match(ie.LocationURL.ToString());
            if (!string.IsNullOrEmpty(match.Value))
            {
                pageURL = ie.LocationURL.ToString();
                return pageURL;
            }
            pageURL = string.Empty;              
        }
        return pageURL;
    }
    - so the URI is completely correct or empty.

    The problem is
    Code:
    IE ie = IE.AttachTo<IE>(Find.ByUrl(uri));
    always throws
    Code:
    WatiN.Core.Exceptions.BrowserNotFoundException: Could not find an IE window matching constraint: Attribute 'href' equals uri '%my_target_URI%'. Search expired after '30' seconds.
    I've googled a lot, but still didn't find any solution :(
    Can anyone help please?
    Thanks.
    Last edited by Mervin; Oct 28 '12, 01:50 PM. Reason: incorrect question title
Working...