Search code examples
c#.netvisual-studio-2013webbrowser-controlawesomium

Awesomium webBrowser control - How Focus on A TextBox


Here is my jquery codes :

    webBrowser_main.ExecuteJavascript("$('input[name=\"username\"]').val('only this one');");
    webBrowser_main.ExecuteJavascript("$('input[name=\"username\"]').click();");
    webBrowser_main.ExecuteJavascript("$('input[name=\"username\"]').focus();");

The first line works very well, But i can't focus on username TextBox.
How can i do that using with Awesomium.Net control?
For the Regular WebBrowser control the codes below works :

    webBrowser_main.Document.GetElementById("username").SetAttribute("value", Username);
    webBrowser_main.Document.GetElementById("username").InvokeMember("click");
    webBrowser_main.Document.GetElementById("username").Focus();

How can i right such these codes for Awesomium control?


Solution

  • try this it should work.

         var javascript = @"(function (){ 
    
               //write JavaScript code here.
              document.getElementById('username').value = 'only this one';
              var a = document.getElementById('username');
              var evnt = a['onclick'];
    
              if (typeof(evnt) == 'function') {
                 evnt.call(a);
              }
             document.getElementById('username').focus();
    
            })()";
    
             webBrowser_main.ExecuteJavascript(javascript );