CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2005
    Posts
    17

    WebBrowser Control - Wait for page to process

    I'm tryna click on an element that opens a window and in the window click on another element. the problem is that when I click that first element it takes some time for the page to process the window so it doesn't click the second element because it's executing the code while it's processing.
    anyone has a solution? I tried sleep() but it's useless because it freezes the webbrowser control so it won't let the window open

  2. #2
    Join Date
    Dec 2010
    Posts
    12

    Re: WebBrowser Control - Wait for page to process

    Use DocumentCompleted event of webbrowser control.

  3. #3
    Join Date
    Nov 2005
    Posts
    17

    Re: WebBrowser Control - Wait for page to process

    I'm not talking about loading a document... I'm talking about an element inside the webpage!
    How can I tell the code to wait until it finishes loading

  4. #4
    Join Date
    Dec 2010
    Posts
    12

    Re: WebBrowser Control - Wait for page to process

    I guess unless all elements are loaded, that event isn't fired at all.

  5. #5
    Join Date
    Nov 2010
    Posts
    34

    Exclamation Re: WebBrowser Control - Wait for page to process

    I had the same problem, and the solution I found is:
    this inside it's own form, all it is is a window with text of "Please wait a moment", and because it's showdialog() you freeze all input and code within the thread, but you don't hold up the thread to prevent the loading of the post processed data after documentcompleted is fired.
    I don't even use documentcompleted in my scenario I just use,
    random code statement;
    wt.showdialog();
    random code;
    wt.showdialog();

    Then within the code below, just adjust the timer for how much of a delay you NEED... It took some tweaking, but I've completely redone what it is I'm working on, so I won't need to use this approach... Instead I'm taking the extra effort of a comparison from each doccompleted... lot's of freakin work.
    Hope this helps though, please do let me know if you find a better way, but I'm dealing with a javascript/ajax page I don't have access to, so this was a stretch of the imagination.



    public partial class WasteTime : Form
    {
    static System.Windows.Forms.Timer timmer = new System.Windows.Forms.Timer();
    public WasteTime()
    {

    InitializeComponent();


    }

    private void WasteTime_Load(object sender, EventArgs e)
    {
    int inter = 1200; //1.2 secs

    timmer.Tick+=new EventHandler(timmer_Tick);
    timmer.Interval = inter;
    timmer.Start();

    }
    private void timmer_Tick(object obj, EventArgs e)
    {
    this.Close();
    timmer.Stop();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured