0

First of all I've repaired WebBrowser and now I see the page correctly in my Windows Form. I folowed this link and referenced it to IE 11.0 so the WebBrowser control in my windows form is a IE11.0 browser instance.

I have this in the constructor of the form:

webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);

then the event handler

public void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    { 
        txtLoad.Text = (Convert.ToInt32((txtLoad.Text)) + 1).ToString();
        var webBrowser = sender as WebBrowser;
        webBrowser.Document.GetElementById("gwt-uid-126").InvokeMember("click");
    }

It all starts with a click of a button :

void BtnTestClick(object sender, EventArgs e)
    {
        webBrowser1.Navigate(@"https://play.google.com/apps/publish/?dev_acc=06010154238306490792#AppListPlace");
    }

The click invoke does nothing . I tried all methods listed here and nothing. Why can I see the button on my screen but cannot reference it in code? Why is documentCompleted firing if the button didn't load already? How can I get the button? and click it?

Community
  • 1
  • 1
kawa
  • 422
  • 4
  • 16
  • If you move the invoke to a new button's click event, wait for the page to load then click the button - does it work? – Alex K. May 15 '14 at 14:22
  • I've tried that also , IT DOES NOT WORK! – kawa May 15 '14 at 14:24
  • This is so weird. I mean I see the button right there! Where is it? Is the WebBrowser control that lame? Maybe it's me but I tried the WatiN library and it worked perfectly smooth with the exception that you can't hide the openDialog window so that threw me off because I need it all done in background while I do other stuff on my computer. – kawa May 15 '14 at 14:26
  • So its unrelated to DocumentCompleted then, rather it seems that there is a problem with the way you are accessing the element. Visit http://www.whatsmyuseragent.com/ in the browser control and check your not in the default IE7 emulation mode – Alex K. May 15 '14 at 14:28
  • 1.You!! Mozilla/5.0 (Windows NT 6.2; Win64; x64; Trident/7.0; rv:11.0) like Gecko – kawa May 15 '14 at 14:29
  • That's IE11. Can you give the URL of the in initial page with the button? – Alex K. May 15 '14 at 14:32
  • https://play.google.com/apps/publish/?dev_acc=06010154238306490792#AppListPlace – kawa May 15 '14 at 14:35
  • @AlexK, will WebClient click and upload files for me? I don't have to display a webbrowser if it's not possible. – kawa May 15 '14 at 15:30

1 Answers1

3

Fix:

webBrowser1.Navigate(@"https://play.google.com/apps/publish/?dev_acc=06010154238306490792#AppListPlace");
while (WebBrowser1.ReadyState != WebBrowserReadyState.Complete) {
         txtLoad.Text = WebBrowser1.ReadyState.ToString();
        Application.DoEvents();
        System.Threading.Thread.Sleep(1);
    }
webBrowser1.Document.GetElementById("gwt-uid-126").InvokeMember("click");


there i a call to the WebBrowserDocumentCompleted event even if the document is not fully loaded.
example:
lets say that there are 2 script elements inside the page source code:

<script src="1.js"></script>
//Here There Is A Call To WebBrowserDocumentCompleted 
<script src="2.js"></script>
//Here There Is A Call To WebBrowserDocumentCompleted
............
body
.............
</html>
//Here There Is A Call To WebBrowserDocumentCompleted

the webbrowser is calling this event even after he done loading script/stylesheet - the page is not really fully loaded yet.

user3633218
  • 56
  • 1
  • 5