1

I'm working with a form that may be a bit over-engineered, and I'm trying to write a script to step through the form and submit it. Most of the form is pretty hackable, but there's a 3-part date input which is just not responding to my attempts to manipulate it programmatically.

The date field works, if I click or tab to it and begin typing. But if I manually dispatch events, even ones that are identical to what it receives when I type and have exactly what the code seems to be looking for, I can't get it to hold onto its values and perform validation. I've tried a lot of variations of this. I've tried manually dispatching a custom event that matches a custom Vue event it should be listening for.

Is there a way to instead manipulate the data of the Vue component directly? To force it to have a certain "monthValue" for example, without intermediate events? I don't expect that there is, but hopefully I'm missing something. Please note that I do have the ability to refactor the form, but that should be an absolute last resort.

2
  • alternate solution: we have working integration tests in selenium which don't run into any issue but I haven't figured out how to reverse engineer them. if anyone knows what webdriver's fillField() method actually does at a granular level, I'd copy that.
    – charcole
    Commented Jan 27, 2023 at 23:31
  • Update: I was able to find a sequence of directly editing the values plus dispatching synthetic input, focus, and blur events which was able to trigger validation. this answer helped me tremendously in constructing a blur event which actually worked: stackoverflow.com/questions/49311741/…
    – charcole
    Commented Feb 2, 2023 at 21:10

1 Answer 1

0

As far as I can tell, no, there isn't a way to do this. But it wasn't necessary.

The solution involved being more careful in looking at what the components were actually trying to do. In this case they were input elements using v-model, which is shorthand for a combination of @input (event listener) and :value attributes[1]. This meant that dispatching synthetic input events with the correct data attribute could convince Vue to accept the value and retain it (whereas any value dispatched in any keyboard event would be ignored entirely). This only addressed half of my problem with this particular form, but it is the correct solution for the question asked.

[1] https://vuejs.org/guide/essentials/forms.html

Not the answer you're looking for? Browse other questions tagged or ask your own question.