I'm trying to fill out 3 select fields in a form like so.
br.select_form(name='frmentermemorableinformation1')
br['frmentermemorableinformation1:strEnterMemorableInformation_memInfo1'] = ['g']
When running the program I get the following error.
ItemNotFoundError: insufficient items with name 'g'
This is the start of the relevant form and the first of 3 select inputs.
<form id="frmentermemorableinformation1" name="frmentermemorableinformation1" method="post" action="/personal/a/logon/entermemorableinformation.jsp" class="validationName:(frmentermemorableinformation1) validate:()" autocomplete="off" enctype="application/x-www-form-urlencoded">
<fieldset class="memInfoSelect clearfix"><div class="formField validate:(oneSelectFieldRequired) validationName:(memorableInformation) clearfix"><div class="formFieldInner"><div class="clearfix"><label for="frmentermemorableinformation1:strEnterMemorableInformation_memInfo1">Character 5  </label><select id="frmentermemorableinformation1:strEnterMemorableInformation_memInfo1" name="frmentermemorableinformation1:strEnterMemorableInformation_memInfo1"><option value="-">Select</option><option value="&nbsp;a"> a</option><option value="&nbsp;b"> b</option><option value="&nbsp;c"> c</option><option value="&nbsp;d"> d</option><option value="&nbsp;e"> e</option><option value="&nbsp;f"> f</option><option value="&nbsp;g"> g</option><option value="&nbsp;h"> h</option><option value="&nbsp;i"> i</option><option value="&nbsp;j"> j</option><option value="&nbsp;k"> k</option><option value="&nbsp;l"> l</option><option value="&nbsp;m"> m</option><option value="&nbsp;n"> n</option><option value="&nbsp;o"> o</option><option value="&nbsp;p"> p</option><option value="&nbsp;q"> q</option><option value="&nbsp;r"> r</option><option value="&nbsp;s"> s</option><option value="&nbsp;t"> t</option><option value="&nbsp;u"> u</option><option value="&nbsp;v"> v</option><option value="&nbsp;w"> w</option><option value="&nbsp;x"> x</option><option value="&nbsp;y"> y</option><option value="&nbsp;z"> z</option><option value="&nbsp;0"> 0</option><option value="&nbsp;1"> 1</option><option value="&nbsp;2"> 2</option><option value="&nbsp;3"> 3</option><option value="&nbsp;4"> 4</option><option value="&nbsp;5"> 5</option><option value="&nbsp;6"> 6</option><option value="&nbsp;7"> 7</option><option value="&nbsp;8"> 8</option><option value="&nbsp;9"> 9</option></select></div>
What exactly am I doing wrong, I tried adding &nbsp;
to the start of g
incase that was the issue but i just get the same error with '&nbsp;g'
replacing 'g'
. Thanks.
Try '& g'..................
This works for me: ' g'
(inside the list)
I don't think there was an easy way to figure out exactly what the correct value was to use in your python code. You don't normally see values like that. I just used mechanize to print out what it thinks the values are:
import mechanize
br = mechanize.Browser()
br.open("http://localhost:8080/1.htm")
br.select_form(name='frmentermemorableinformation1')
select = br.form.find_control("frmentermemorableinformation1:strEnterMemorableInformation_memInfo1",
type='select')
for item in select.items:
print item.attrs['value']
--output:--
-
a
b
c
d
e
f
g
...
...
I guess I should look up some html to understand why it wanted me to enter the string rather than the value and what does and why amp isnt present in the string version.
There are certain characters that are illegal inside html. For instance, one of them is '<' because it looks like the start of a tag. But what if you want to display 'x < 3' on your html page? Html provides a syntax that lets you include illegal characters inside html using what are called 'html entities'. To include a '<' character on your page, you use the html entity <
("less than"). Html entities start with an '&', are followed by some numbers or some characters which represent the illegal character, and end with a semi-colon.
Because html entities start with an '&', that means you can't write '&' in your html when you want to display the '&' character on your page--because html will think the '&' is the start of an html entity. So you have to use an html entity for '&', which happens to be &
("ampersand").
There is an html entity
("non-breaking space"), which creates a space in html. Generally, html collapses all white space, so
is used to create spaces that won't collapse. However, note that in the value attributes of the options, it is written 'nbsp;', which is not an html entity because it doesn't start with '&', so it is just a series of characters that is part of the value. So each option's value is a combination of:
& (represented by an html entity as required)
and the characters:
nbsp;g
Those are really strange values.