Hello,
Just some background:We are using a WebView in a VB.NET Windows Form Application running .NET Framework 4.7.2 to automate filling out online forms using the EvalScript method. For example, we will fill an input box with an Id number, then send 'Tab' to navigate away from the element:
Code: Visual Basic.NET
webView.EvalScript("document.getElementById('Dc-c').click();")
webView.EvalScript("document.getElementById('Dc-c').value='" & idnumber & "';")
webView.SendKeyEvent(True, EO.WebBrowser.KeyCode.Tab)
We also use a WebView in a C# .NET 8 Web API project. This WebView is headless and is run inside a ThreadRunner. For the majority of websites, they work the same. However, there are cases where on certain websites when we set a value, it disappears when we navigate away from the input field, as if the value was never set at all. For example, running the identical commands as above results in the input not holding any value:
Code: C#
webView.EvalScript("document.getElementById('Dc-c').click();");
webView.EvalScript($"document.getElementById('Dc-c').value='{idnumber}';");
webView.SendKeyEvent(true, EO.WebBrowser.KeyCode.Tab);
We have tried setting the value directly as shown above, and also by focusing on the element and sending each char individually using .SendChar(). We tried to force the element to update by using the JavaScript "dispatchEvent(new Event('input', { bubbles: true })" to force any updating that may need to occur. However, no matter what we try, no value is set in these inputs. The strange thing is that these same sites work fine in the UI WebView version.
Our QuestionWe are struggling to identify why the same exact logic works perfectly fine not using ThreadRunner in a UI application, but fails to work headless using ThreadRunner. Could anyone help shed some light on why this may be the case, if there are any workarounds, or if anyone has shared a similar experience?
Thank you!