By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

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

P: 1
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:
Expand|Select|Wrap|Line Numbers
  1. private void GetHtmlCode()
  2. {
  3.     string uri = GetTargetURI();
  4.     if(!string.IsNullOrEmpty(uri))
  5.     {
  6.         IE ie = IE.AttachTo<IE>(Find.ByUrl(uri));
  7.         htmlCode = ie.Eval(JavaScriptToRun);
  8.     }
  9.     else
  10.     {
  11.         MessageBox.Show("Target page is not opened",
  12.                         "Notification", MessageBoxButtons.OK);
  13.     }
  14. }
And there's a method for getting URI:
Expand|Select|Wrap|Line Numbers
  1. private string GetTargetURI() //проверка URL
  2. {
  3.     Regex reg;
  4.     Match match;
  5.     foreach(SHDocVw.InternetExplorer ie in shellWindows)
  6.     {
  7.         reg = new Regex(patternURL);
  8.         match = reg.Match(ie.LocationURL.ToString());
  9.         if (!string.IsNullOrEmpty(match.Value))
  10.         {
  11.             pageURL = ie.LocationURL.ToString();
  12.             return pageURL;
  13.         }
  14.         pageURL = string.Empty;              
  15.     }
  16.     return pageURL;
- so the URI is completely correct or empty.

The problem is
Expand|Select|Wrap|Line Numbers
  1. IE ie = IE.AttachTo<IE>(Find.ByUrl(uri));
always throws
Expand|Select|Wrap|Line Numbers
  1. 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.
Oct 28 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.