0

I'm working on a chrome extension that will fill out forms on different web pages. I'm getting stuck when I reach a site that uses angular. Sometimes I can manipulate the DOM and get the form to fill, but if I run into an ng-select field for instance, there is no easy way for me to fill the form. Some libraries expose public methods and make it easy to interact with their components. Does Angular expose a public api? Is there a way to interact with an Angular programmatically from the DOM in production?

Here is an example page: https://icaeservices.ica.gov.sg/sgarrivalcard/ . If you follow the link and click on individual submission you will get to a form that uses ng-select fields. Is it possible to fill these select fields from the DOM?

doublea
  • 447
  • 1
  • 4
  • 11
  • Simply do element.dispatchEvent(new Event('change', {bubbles: true})) and/or use document.execCommand ([example](/a/57900849)). – wOxxOm Dec 13 '19 at 12:45
  • Thanks for your input, but emitting a change event doesn't cause all the necessary JS to trigger. The execCommand is interesting, and gets me part way there but not all the way. I updated my question with an example web page that uses `ng-select` menus – doublea Dec 13 '19 at 15:09
  • I see in devtools the `input` element uses both `change` and `input` events so just dispatch 'input'. – wOxxOm Dec 13 '19 at 15:20
  • I tried both events with no luck. After focusing for example the nationality input, I can call `document.execCommand('insertText', false, 'cuban')` and the input will fill and the dropdown options narrow, but triggering the events after have no effect. I'm dispatching the event on the input element, `inputEle.dispatchEvent(new Event('input', {bubbles: true}))`. Can you get it to work? – doublea Dec 13 '19 at 15:33
  • 1
    It works in the sense that the dropdown shows the value but the form wants the user to click on a `span` entry inside `ng-dropdown-panel-items` so you'll have to simulate that `click` event. – wOxxOm Dec 13 '19 at 15:37
  • Ok, I was hoping to find a way around simulating clicks but that route will work – doublea Dec 13 '19 at 15:47

0 Answers0