3 Replies - 5718 Views - Last Post: 09 July 2012 - 03:55 AM Rate Topic: -----

#1 merlol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-July 12

Error in loop

Posted 09 July 2012 - 01:58 AM

Hi I got this error , actually this is the algorithm error? WebBrowser method "GetAttribute" making to error 2th the return.

        HtmlElementCollection classButton;
        List<string> aaa = new List<string>();
private void webBrowser1git()
        {
                Regex ma1 = new Regex("google", RegexOptions.IgnoreCase);
                Regex ma2 = new Regex("blogger", RegexOptions.IgnoreCase);
                
                classButton = webBrowser1.document.GetElementsByTagName("A");

                foreach (HtmlElement element in classButton)
                {
                    if (sayac == 10)
                    {
                        break;
                    }
                    
                        MatchCollection test1 = ma1.Matches(element.GetAttribute("href")); //<< ERROR LINE 
                                                                                           //  1th return is OK
                                                                                           //  2th return is FAIL
                       //ERROR LINE "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"


                        MatchCollection test2 = ma2.Matches(element.GetAttribute("href"));
                    
                    if (test1.Count == 0 && test2.Count == 0)
                        {
                            //aaa.Add(element.GetAttribute("href"));
                            sayac++;
                            element.InvokeMember("click");
                            try
                            {
                                
                                while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
                                {
                                    Application.DoEvents();
                                }
                                MessageBox.Show(webBrowser1.ReadyState.ToString());
                            }
                            catch (ObjectDisposedException exception)
                            {
                                MessageBox.Show("Caught: {0}", exception.Message);
                            }
                            Thread.Sleep(2000);
                            MessageBox.Show(webBrowser1.Url.ToString() + "            1");
                            
                            //webBrowser1.GoBack();

                            /*try
                            {
                                while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
                                {
                                    Application.DoEvents();
                                }
                                MessageBox.Show(webBrowser1.Url.ToString()+"            2");
                                Thread.Sleep(3000);

                            }
                            catch (ObjectDisposedException exception)
                            {
                                MessageBox.Show("Caught: {0}", exception.Message);
                            }*/
                            webBrowser1.GoBack();
                            try
                            {
                                while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
                                {
                                    Application.DoEvents();
                                }
                                MessageBox.Show(webBrowser1.Url.ToString() + "            2");
                            }
                            catch (ObjectDisposedException exception)
                            {
                                MessageBox.Show("Caught: {0}", exception.Message);
                            }
                            MessageBox.Show(webBrowser1.Url.ToString() + "            3");
                        }
                  
                }
        }




Is This A Good Question/Topic? 0
  • +

Replies To: Error in loop

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6245
  • View blog
  • Posts: 24,013
  • Joined: 23-August 08

Re: Error in loop

Posted 09 July 2012 - 02:42 AM

Matches is a MatchCollection, so you might want to check out the first property listed on that page.
Was This Post Helpful? 0
  • +
  • -

#3 merlol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-July 12

Re: Error in loop

Posted 09 July 2012 - 03:35 AM

    HtmlElementCollection classButton;
        List<string> aaa = new List<string>();
private void webBrowser1git()
        {

                
                classButton = webBrowser1.document.GetElementsByTagName("A");

                Regex ma1 = new Regex("google", RegexOptions.IgnoreCase);
                Regex ma2 = new Regex("blogger", RegexOptions.IgnoreCase);



                foreach (HtmlElement element in classButton)
                {
                    if (sayac == 10)
                    {
                        break;
                    }

                    MatchCollection test1 = ma1.Matches(element.GetAttribute("href"));
                    MatchCollection test2 = ma2.Matches(element.GetAttribute("href"));
                    if (test1.Count == 0 && test2.Count == 0)
                    {
                        sayac++;    
                        aaa.Add(element.GetAttribute("href"));
                    }
                }

                foreach (HtmlElement element in classButton)
                {

                        /*Regex ma1 = new Regex("google", RegexOptions.IgnoreCase);
                        Regex ma2 = new Regex("blogger", RegexOptions.IgnoreCase);
                        MatchCollection test1 = ma1.Matches(element.GetAttribute("href"));
                        MatchCollection test2 = ma2.Matches(element.GetAttribute("href"));*/
                    foreach(string link in aaa)
                    {


//1th loop : no error
//2th loop : element.GetAttribute("href") => "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"


                    if (element.GetAttribute("href") == link)
                        {
                            element.InvokeMember("click");
                            try
                            {
                                
                                while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
                                {
                                    Application.DoEvents();
                                }
                                MessageBox.Show(webBrowser1.ReadyState.ToString());
                            }
                            catch (ObjectDisposedException exception)
                            {
                                MessageBox.Show("Caught: {0}", exception.Message);
                            }
                            Thread.Sleep(2000);
                            MessageBox.Show(webBrowser1.Url.ToString() + "            1");
                            
                            //webBrowser1.GoBack();

                            /*try
                            {
                                while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
                                {
                                    Application.DoEvents();
                                }
                                MessageBox.Show(webBrowser1.Url.ToString()+"            2");
                                Thread.Sleep(3000);

                            }
                            catch (ObjectDisposedException exception)
                            {
                                MessageBox.Show("Caught: {0}", exception.Message);
                            }*/
                            webBrowser1.GoBack();
                            try
                            {
                                while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
                                {
                                    Application.DoEvents();
                                }
                                MessageBox.Show(webBrowser1.Url.ToString() + "            2");
                            }
                            catch (ObjectDisposedException exception)
                            {
                                MessageBox.Show("Caught: {0}", exception.Message);
                            }
                            MessageBox.Show(webBrowser1.Url.ToString() + "            3");
                        }

                }
                  
                }
        }



Was This Post Helpful? 0
  • +
  • -

#4 merlol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-July 12

Re: Error in loop

Posted 09 July 2012 - 03:55 AM

Hmmm ok ok, I understand that. This is algorithm error; on the WebBrowser class methods "InvokeMember("click");" and after "webBrowser1.GoBack();".Algorithm clicking the link and after returning old page, but old page not available on the 2th loop.Therefore shows the error message, like this "Access is denied.". Ok this is not a problem, I solve this error.

Thank you jackofalltrades.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1