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

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -