0

I am trying to SendKeys to a user control which has a web browser inside. I haven't found a decent solution apart from copying the data to a clipboard and pasting it inside the control with a button. Can anyone help on this? I don't currently have any code for this yet.

I've tried:

this.webBrowser1.Focus();
SendKeys.SendWait("example");

However, I don't know how to position the code to target the user controls and web browser in the fashion I want it.

Does anybody know how to do this?

janw
  • 8,758
  • 11
  • 40
  • 62
  • The following may be helpful: [Introduction to WebView2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/), https://stackoverflow.com/questions/65452473/how-to-click-button-in-c-sharp-webview/65470588#65470588 and https://stackoverflow.com/questions/68578936/javascript-scripts-in-html-not-firing-from-winform-webbrowser-control/68592056#68592056 – Tu deschizi eu inchid Nov 06 '22 at 01:23
  • I know it can be done but it's been many years since I needed to. Now days these forms applications and controls seems pretty outdated. But some googling should net you an answer. e.g. maybe something like this https://social.msdn.microsoft.com/Forums/en-US/f3d27684-c2e8-4f84-80f6-fa1220a3d85d/i-have-a-c-program-and-i-need-to-simulate-a-mouse-click-in-a-webbrowser-window-how-would-i-go?forum=csharplanguage edit this makes it look simple: https://stackoverflow.com/questions/5150610/how-to-simulate-mouse-click-with-the-webbrowser-control – Joe_DM Nov 06 '22 at 03:49
  • as an aside, if you're looking for an option to do web automation. Selenium might be a good option to automate controlling a native browser like chrome. – Joe_DM Nov 06 '22 at 03:54

1 Answers1

0

If this is a WinForm application and it has a browser control it must have a property for src or href to hold the url of a page you can make use of that.

But you can also use SendKeys to copy/paste content to/from clipboard:

SendKeys.SendWait("^(c)");

will copy the selected to clipboard and

SendKeys.SendWait("^(v)");

will paste it for you in the current cursor position. enter image description here

Vinod Srivastav
  • 3,644
  • 1
  • 27
  • 40