'C# Chromium browser whatsapp web send message using textbox
I already follow the Chromium user guide, still doesn't work. Using my C# program, I want to send message or image via whatsapp web by cascading the textbox in my program with the message box of whatsapp. This is my code
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Windows.Forms;
namespace ChromiumwithEditorWsWeb
{
public partial class Form1 : Form
{
ChromiumWebBrowser browser;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
browser = new ChromiumWebBrowser("http://web.whatsapp.com");
browser.Dock = DockStyle.Fill;
panel1.Controls.Add(browser);
}
private void buttonBack_Click(object sender, EventArgs e)
{
browser.Back();
}
private void buttonForward_Click(object sender, EventArgs e)
{
browser.Forward();
}
private void buttonReload_Click(object sender, EventArgs e)
{
browser.ShowDevTools();
}
private void buttonGo_Click(object sender, EventArgs e)
{
browser.Load(textBoxUrl.Text);
}
private void buttonPhoneNo_Click(object sender, EventArgs e)
{
browser.EvaluateScriptAsync("document.GetElementsByClass('jN-F5 copyable-text selectable-text').value = textBoxPhone.Text");
browser.EvaluateScriptAsync("document.GetElementsByClass('_2S1VP copyable-text selectable-text').value = textBoxMessage.Text");
}
}
}
Help it! Give suggestions for the best step.
Solution 1:[1]
Clipboard.SetText(msg);
Thread.Sleep(TimeSpan.FromSeconds(2));
SendKeys.Send(msg); //SendKeys.SendWait("^{V}");
Thread.Sleep(TimeSpan.FromSeconds(1));
SendKeys.SendWait("{ENTER}");
Not a good solution though, as it requires the windows to be on focus and this uses the clipboard. But it works !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kumarakuru |
