skip to Main Content

I am trying to automate a web entry form with C# using WebView2.

Web entry form has three DOM Elements: Input (UserName/Password) and Entry Button (disabled).

If you enter value to input areas by keyboard (manually) Entry Button is enabled. But sending Java Scripts to set value of input boxes do not make this button enabled. Of course it is a guard to disable automation of this page…

Is there a way to make Entry Button enabled with java script?

Page image is below:

Form Entry

2

Answers


  1. It seems that site owner has arranged actions for ‘Entry Button’ will be enabled only by keystroke. Guard against automation…

    To simulate keystroke action you may use below code for each DOM element:

    document.getElementById('USERNAME').focus();
    document.execCommand('insertText', false, 'YourName');
    document.getElementById('PASSWORD').focus();
    document.execCommand('insertText', false, 'Password');
    document.getElementById('ENTRY').click();
    

    This will activate ‘Entry Button’ by pasting your data like keystrokes…

    Login or Signup to reply.
  2. For those interested I’ve just released WebView2.DevTools.Dom to NuGet.org. It’s free for anyone to use.

    More details and examples in the Readme

     await webView.EnsureCoreWebView2Async();
     
    // Add using WebView2.DevTools.Dom; to access the CreateDevToolsContextAsync extension method
     await using var devToolsContext = await webView2Browser.CoreWebView2.CreateDevToolsContextAsync();
    
    // Get element by Id
    // https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
    var userName = await devtoolsContext.QuerySelectorAsync("#USERNAME");
    
    //Type text in an input field
    await userName.TypeAsync("myusername");
    
    var password = await devtoolsContext.QuerySelectorAsync("#PASSWORD");
    
    //Type text in an input field
    await password.TypeAsync("mypassword");
    
    var button = await devtoolsContext.QuerySelectorAsync("#BUTTON");
    
    //Click The element
    await button.ClickAsync();
    

    This will simulate both key presses and mouse move/clicks.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search