0

I am struggling with trying set some input on one of third party webpages that has an angular-related fields validation. When I only set the value attribute by chrome browser or with cefsharp, in both cases, the value is not being set.

I have found a walkaround - to enter one char in required fields to make it ng-touched and then set the js value attribute of it.

  1. In CefSharp, I am creating the KeyEvent and then I am sending it
  2. Then, I am setting the value of the field using CefSharp's EvaluateScriptAsync or ExecuteJavaScriptAsync When I am doing it manually with browser, it works but under cefsharp it is not working - it sets the one char in both fields, but then, after changing the value of fields and verifying it in 3 ways does not work:

1)reading the value by EvaluateScriptAsync/ExecuteJavaScriptAsync The value is being set correctly, but at the end, there is only a first change applied 2)rendering a html by GetSourceAsync() - it renders temporarily the result page with first pre-change only 3)also the same with screenshot functionality of cefsharp

Of course I am unable to use Angular Development tools plugin, because app is in production mode.

What I have also tried: -using Thread.Sleep with many timespans - did not help -input.dispatchEvent(new Event('input',{bubbles:true})) - same effect as previous

  • multiple changes of value pre-set - same effect
  • multiple setting of a final value - the same

The only working solution I have created was to focus on every required field, then iterate over every string as single char and send it as single key, but it was unefficient and had been refused :(

mlawicki
  • 1
  • 1

1 Answers1

0

Angular is made to work with a user, not a bot.

This means it works best when you simulate clicks & moves, rather than directly putting the data where you want.

Where you do

- get input
- set value

Try instead doing

- get input
- focus it
- set value
- blur it

Angular should detect changes better this way.

If it does not work, try directly clicks and keystrokes in the input, instead of settign your value programmatically.

MGX
  • 2,534
  • 2
  • 14
  • Thank you for the answer. Forgot to mention - I was also trying to blur using sending the tab and verified, if this tab had been sent. Tab has been sent but it did not help. Now I have tried with blurring using .blur() but with the same effect. I will try with clicking and sending the keystrokes then. – mlawicki Oct 13 '22 at 11:40
  • @mlawicki the idea is the closer to a real human being you are, the better it will work. So yes, keystrokes are the best option to let angular update itself, but you can maybe try the `change` event instead of `input`, see if it works ? – MGX Oct 13 '22 at 11:42
  • also tried with firing the 'change' event before creating the topic, forgot to mention, but did not work – mlawicki Oct 13 '22 at 11:47