-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form elements not updated when making DOM changes #2140
Comments
Possible solution:
OR... ...just add a method to reconstruct the elements of a form (will have to be called explicitly) |
Yes, the form control elements in FormElement.elements() are specifically associated during the parse; they are not a runtime property. I think if they are required, a reconstruction method would be the most appropriate. I would be happy to review a PR if you want to add it. But, can you tell me what you are actually using those elements for? There may be a simpler solution, or a more ergonomic change we can make. |
For making automated HTTP requests to a website (as in submitting a form). I'm parsing all the elements as they come and just setting the values I need. Some forms are modified dynamically in the browser and I need to mirror those modifications. |
Thanks for confirming. That's definitely the main point of the FormElement, so we should make sure its use is ergonomic. The main reason that we have the linking running at parse time is so that form element children that are moved out from the containing Some rough thoughts: Associating the new elements with the form automatically would be convenient, but may have a bit of an overhead and a low hit ratio. Linking it to the retrieval of the form would be ideal, but in your example it's just a plain cast so we don't have that opportunity. We do if the user is calling it via Elements#forms(). Maybe we can add a Element#asForm() method that runs a re-connect and simplifies the cast. But in review of the code and use. I think it's best to reimplement |
Thanks, done. @aditsu it would be great if you could review and test (do a |
I am parsing an html document and making some changes to it, then extracting some form fields. It looks like the
elements
inFormElement
are already set when the document is initially parsed, and remain unchanged.Example code:
The result shows that the form now has the
bar
andbaz
fields, but itselements
are stillfoo
andbar
. Notice thatfoo
was removed even before selecting the form element.Workaround (re-parsing):
form = (FormElement) Jsoup.parse(form.toString()).selectFirst("form");
Jsoup version: 1.17.2
The text was updated successfully, but these errors were encountered: