python - Mechanize select from dropdown -


i want mechanize check if current value of selected dropdown = default value, mechanize choose value in list instead. html of dropdown follow:

            <td class="label">list</td>             <td>                 <select name="list" id="list" onchange="list()">                     <option>---</option>                  <option value='1'>1</option> <option value='2'>2</option> ---other options--- 

my code is:

if br.form["list"] == "---":     br.form["list"].value = "1"     r = br.form["list"]     print(r) 

however list value still returns:

   ['---'] 

any idea?

you need specify value list:

if br.form["list"] == ["---"]:     br.form["list"].value = ["1"] 

according mechanize - forms documentation:

# controls represent lists (checkbox, select , radio lists) # listcontrol instances.  values sequences of list item names. # come in 2 flavours: single- , multiple-selection: form["favorite_cheese"] = ["brie"]  # single form["cheeses"] = ["parmesan", "leicester", "cheddar"]  # multi 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -