Click here to Skip to main content
15,071,480 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
I'm trying to figure out how to auto fill two text box's located on a website embedded in my windows form via two text box's also on my windows form. The Id of one of the text box's is Email. The other textbox's Id is Password. I know I can find the element Id of the text box's on the embed browser in my windows form by using this code below. I will post the definition first.

public void ExecuteScriptAsync(string script);

This is the code used to get the Id.



Which in turn I can set the value/text of said text box's by using this code. The below code works great and will set the value/text of both text box's.

browser.ExecuteScriptAsync("document.getElementById('Email').value= 'USER EMAIL STRING'");

browser.ExecuteScriptAsync("document.getElementById('Password').value= 'USER PASSWORD STRING'");

I have two text boxes on my windows form named txtEmail and txtPassword that I would like to use so the user can put his or her own login information. I tried to achieve this among other ways by passing the txtEmail.Text and txtPassword.Text in the code below which doesn't work.

string Email = @"""document.getElementById('Email').value= " + @"'" + txtEmail.Text + @"'""";

string Password = @"""document.getElementById('Password').value= " + @"'" + txtPassword.Text + @"'""";


I don't get any errors inside the developer IDE. It just won't set the text box's text in the embedded browser. Can someone explain how to use a text box on my windows form to pass along the needed strings?

Edit: Reworded the question in better detail. Hope it better helps explain my question.
Updated 14-Nov-20 22:48pm
Sergey Alexandrovich Kryukov 31-Aug-14 21:56pm
Fist and main question: why?

There is not such thing as "getElementById value". getElementById is a function which actually searched for the element.

Just be logical: how can you set the attribute value using any "get***" method? :-)
If you need to set attribute value, set it.

ChintanShukla 1-Sep-14 1:37am
Why dont you simply use runat="server".

I figured it out by myself. None the less here is the code needed to supply a text box's data into the string. So you can use it in conjunction with the script for ExecuteScriptAsync in CefSharp if the form has two text box's respectively with the ID's Email and Password.

browser.ExecuteScriptAsync("document.getElementById('Email').value=" + '\'' + txtEmail.Text + '\'');
                    browser.ExecuteScriptAsync("document.getElementById('Passwd').value=" + '\'' + txtPassword.Text + '\'');
private void browserView1_FinishLoadingFrameEvent (object sender, FinishLoadingEventArgs e)


if (e.IsMainFrame)


   DOMDocument document = e.Browser.GetDocument();
   DOMInputElement userName = (DOMInputElement)document.GetElementByName("j_username");
   DOMInputElement pass = (DOMInputElement)document.GetElementByName("j_password");                    
   userName.Value = "HackStar";
   pass.Value = "HackStar";  

Richard Deeming 26-Feb-18 12:09pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900