title: Get URL from Opera browser
body: <p>I am trying to get URL from Opera browser, I assumed it is the same as for Chrome but I was wrong since it doesn't work this way.</p>
  
  <p>whatever I have done so far is:</p>
  
  <pre><code>    public static string GetURL(IntPtr intPtr, string programName, out string url)
      {
          string temp = null;
              if (programName.Equals("opera"))
          {
          //    // there are always multiple opera processes, so we have to loop through all of them to find the
          //    // process with a Window Handle and an automation element of name "Address and search bar"
            /*  string x = "";
              DdeClient dde = new DdeClient("opera", "WWW_GetWindowInfo");
              try
              {
                  //temp := RequestData('0xFFFFFFFF');
                  dde.Connect();
                  string url1 = dde.Request("URL", int.MaxValue);
                  string[] text = url1.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries);
                  dde.Disconnect();
              }
              catch (Exception)
              {
                  x = "failed";
               }
  */
  
  
  
              Process[] procsOpera = Process.GetProcessesByName("opera");
              foreach (Process opera in procsOpera)
              {
                  // the chrome process must have a window
                  if (opera.MainWindowHandle == IntPtr.Zero)
                 {
                        continue;
                  }
  
                  // find the automation element
                  AutomationElement elm = AutomationElement.FromHandle(opera.MainWindowHandle);
                  AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants,
                    new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));
  
                  // if it can be found, get the value from the URL bar
                  if (elmUrlBar != null)
                  {
                      AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns();
                      if (patterns.Length &gt; 0)
                      {
                          ValuePattern val = (ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0]);
                          temp = val.Current.Value.ToString();
                          url = val.Current.Value.ToString();
                      }
                      else
                      {
                          temp = "";
                          url = "";
                      }
                  }
                  else
                  {
                      temp = "";
                      url = "";
                  }
              }
          }
          url = temp;
          return temp;
      }
  </code></pre>
  
  <p>I have tried it with both NDDE client and automation element, but both are failed :(
  I think in automation element the problem is in this line </p>
  
  <pre><code>AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));
  </code></pre>
  
  <p>Perhaps for opera it isn't <code>"Address and search bar"</code> can some 1 help me to solve the issue please? </p>
  
  <p><strong>NOTE:</strong> There are couple question where chrome and opera tagged but there is no Opera working answer inside on SO.</p>