So, I will give you, it was quite difficult to understand. To take a literal look at mechanize code to understand. Unfortunately, I could not check it on the actual form element without the name attribute, although I can do this if you provide the site that you are trying to pull out, or you can do it yourself.
Form objects are honestly not as well implemented for ease of use. The only way you can edit the control value of an anonymous form is to use the set_value method:
class HTMLForm:
So, what will you do here to set the control you are looking for, use the nr argument to capture it using the index of the control on the form. Unfortunately, you cannot use negative integers to grab controls from the back, so to grab the last form, you need to do something on the lines nr=len(myform.controls)-1 .
In any case, what you can do here is to use the set_value method, and you should be set as follows:
forms[2].set_value("LOOK!!!! I SET THE VALUE OF THIS UNNAMED CONTROL!", nr=5)
and that should work for you. Let me know how this happens.
source share