0

I am using the CefSharp Chromium Webbrowser and I wanted to login on a website.

That´s my code so far:

   Private WithEvents browser As ChromiumWebBrowser
    Public Sub New()
        InitializeComponent()
        Dim settings As New CefSettings()
        CefSharp.Cef.Initialize(settings)
        browser = New ChromiumWebBrowser("mysite.com/login") With {
            .Dock = DockStyle.Fill
        }
        panBrowser.Controls.Add(browser)
    End Sub

That´s working. Now I wanted to fill the username and password textbox. I archieved it like this:

browser.ExecuteScriptAsync("document.getElementById('login-username').value = 'user@gmail.com'")
browser.ExecuteScriptAsync("document.getElementById('login-password').value = 'password'")

That´s working too, I can see my credentials entered. But when I press login, it tells me, that the textfields are empty. When I type in a letter by myself, it´s working. Why? Is there another way to enter the credentials with JS or CefSharp?

Thank you very much :)

  • Does that site work with a password manager filling the fields? I just wonder whether there's some script catching keystrokes to prevent automated logins. That's a complete guess but the only reason I can think of. – jmcilhinney Jun 02 '20 at 08:13
  • When I use the passwordmanager "Keeper", it works, when Keeper types in my credentials.. – Rene Bischof Jun 02 '20 at 08:17
  • Try setting both Value and InnerText of those elements. – Jimi Jun 02 '20 at 09:21
  • As @jmcilhinney suggests it's very common for websites to validate key presses. You can programatically generate key presses see https://stackoverflow.com/a/53452094/4583726 for an example. You maybe able to generate key presses in javascript see https://stackoverflow.com/a/59113178/4583726 – amaitland Jun 02 '20 at 09:31
  • @Jimi No success.. amaitland: When I use your first link, I have to pass a WindowsKeyCode but it can only be Uppercase, that´s not good for me.. – Rene Bischof Jun 02 '20 at 13:07
  • @ReneBischof you are not limited to upper case. For a very basic example see https://github.com/cefsharp/CefSharp/blob/cefsharp/83/CefSharp.OffScreen.Example/Program.cs#L99 – amaitland Jun 03 '20 at 06:50
  • Can you past the HTML of these 3 fields? Is it a form being submitted? I would suggest you immediately open the devtools for the browser and then play around with the console and JavaScript. You can add your values and then use JavaScript to see what the browser actually recognised as being in the boxes. – darbid Jun 13 '20 at 18:33

0 Answers0