Question

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 &#160;</label><select id="frmentermemorableinformation1:strEnterMemorableInformation_memInfo1" name="frmentermemorableinformation1:strEnterMemorableInformation_memInfo1"><option value="-">Select</option><option value="&amp;nbsp;a">&nbsp;a</option><option value="&amp;nbsp;b">&nbsp;b</option><option value="&amp;nbsp;c">&nbsp;c</option><option value="&amp;nbsp;d">&nbsp;d</option><option value="&amp;nbsp;e">&nbsp;e</option><option value="&amp;nbsp;f">&nbsp;f</option><option value="&amp;nbsp;g">&nbsp;g</option><option value="&amp;nbsp;h">&nbsp;h</option><option value="&amp;nbsp;i">&nbsp;i</option><option value="&amp;nbsp;j">&nbsp;j</option><option value="&amp;nbsp;k">&nbsp;k</option><option value="&amp;nbsp;l">&nbsp;l</option><option value="&amp;nbsp;m">&nbsp;m</option><option value="&amp;nbsp;n">&nbsp;n</option><option value="&amp;nbsp;o">&nbsp;o</option><option value="&amp;nbsp;p">&nbsp;p</option><option value="&amp;nbsp;q">&nbsp;q</option><option value="&amp;nbsp;r">&nbsp;r</option><option value="&amp;nbsp;s">&nbsp;s</option><option value="&amp;nbsp;t">&nbsp;t</option><option value="&amp;nbsp;u">&nbsp;u</option><option value="&amp;nbsp;v">&nbsp;v</option><option value="&amp;nbsp;w">&nbsp;w</option><option value="&amp;nbsp;x">&nbsp;x</option><option value="&amp;nbsp;y">&nbsp;y</option><option value="&amp;nbsp;z">&nbsp;z</option><option value="&amp;nbsp;0">&nbsp;0</option><option value="&amp;nbsp;1">&nbsp;1</option><option value="&amp;nbsp;2">&nbsp;2</option><option value="&amp;nbsp;3">&nbsp;3</option><option value="&amp;nbsp;4">&nbsp;4</option><option value="&amp;nbsp;5">&nbsp;5</option><option value="&amp;nbsp;6">&nbsp;6</option><option value="&amp;nbsp;7">&nbsp;7</option><option value="&amp;nbsp;8">&nbsp;8</option><option value="&amp;nbsp;9">&nbsp;9</option></select></div>

What exactly am I doing wrong, I tried adding &amp;nbsp; to the start of g incase that was the issue but i just get the same error with '&amp;nbsp;g' replacing 'g'. Thanks.

Was it helpful?

Solution

Try '& g'..................

This works for me: '&nbsp;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:--
-
&nbsp;a
&nbsp;b
&nbsp;c
&nbsp;d
&nbsp;e
&nbsp;f
&nbsp;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 &nbsp; 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 &lt; ("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 &amp; ("ampersand").

There is an html entity &nbsp; ("non-breaking space"), which creates a space in html. Generally, html collapses all white space, so &nbsp; 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top