简体   繁体   中英

Pasting text into web browser C#

I would like to paste some text into a web browser element. For example:

private void pasteBtn_Click(object sender, EventArgs e){
    WebBrowser1.PasteString("some text");
}

PasteString() Clearly doesnt exist but you get what i mean.

I have just tried pasting the string outright with a button, but the browser loses focues before it pastes.

I have tried many thing but none of them work. Anything would help, i just wanna paste a string into a textbox on a website with a button, or something alike.

Lets' say your web page loaded inside the WebBrowser has an input element like this:

<input type="text" id="theHtmlInputElemId" >

I think you need something like this:

NB not tested

private void pasteBtn_Click(object sender, EventArgs e){
    var inputElement = WebBrowser1.Document.GetElementById("theHtmlInputElemId");
    inputElement.SetAttribute("value", theStringToPaste);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM