0

I have a C# Winform app using CefSharp that logs into a website. The site changed the login screen and now when I set the value of the elements for the userid and password, they are not retained in the element properties.

I have tried setting both the defaultValue and value properties of the elements, but when the code executes the "click" the values disappear from the input fields and the login fails.

//Enable the login button
chromeBrowser.ExecuteScriptAsync("document.getElementsByTagName('BUTTON')[0].disabled='false';");

//Set the userID on the login form
chromeBrowser.ExecuteScriptAsync("document.getElementsByClassName('form-control__formControl___3uDUX')[1].defaultValue=" + '\'' + userID + '\'');

chromeBrowser.ExecuteScriptAsync("document.getElementsByClassName('form-control__formControl___3uDUX')[1].value=" + '\'' + userID + '\'');

//Set the password on the login form
chromeBrowser.ExecuteScriptAsync("document.getElementsByClassName('form-control__formControl___3uDUX')[2].defaultValue=" + '\'' + passWord + '\'');

chromeBrowser.ExecuteScriptAsync("document.getElementsByClassName('form-control__formControl___3uDUX')[2].value=" + '\'' + passWord + '\'');

//Click the login button
chromeBrowser.ExecuteScriptAsync("document.getElementsByTagName('BUTTON')[0].[0].click();");

I've noticed through keying in the values directly on the page that the userid and password are passed to a react event

__reactEventHandlers$41017fwaadp:
autoFocus: true
className: "form-control__formControl___3uDUX"
data-automation-id: "uname"
disabled: false
maxLength: undefined
onBlur: ƒ ()
onChange: ƒ ()
onFocus: ƒ ()
onKeyPress: ƒ ()
onKeyUp: ƒ ()
onPaste: ƒ ()
placeholder: undefined
readOnly: false
type: "text"
value: ""

Setting the values through code fails to pass the value.

Jimenemex
  • 3,104
  • 3
  • 24
  • 56
Ruger
  • 1
  • 2
  • Try [removing all listeners](https://stackoverflow.com/a/39026635/8043806) from the elements before setting their values – Giddy Naya Aug 13 '19 at 19:04
  • Tried doing "document.querySelector('body').outerHTML = document.querySelector('body').outerHTML" to remove the event listeners and that allowed the userid and password to be retained. However, when the "click" is invoked on the button the login still fails. – Ruger Aug 22 '19 at 21:54

0 Answers0