Using Python Mechanize, for example, "Tamper Data"

I am writing a web testing script using python (2.6) and mechanize (0.1.11). On the page I'm working with, there is an html form with the selected field as follows:

<select name="field1" size="1">
    <option value="A" selected>A</option>
    <option value="B">B</option>
    <option value="C">C</option>
    <option value="D">D</option>
</select>

In mechanization, if I try something like this:

browser.form['field1'] = ['E']

Then I get the error message: ClientForm.ItemNotFoundError: insufficient items with name 'E'

I can do this manually with the Firefox extension "Tamper Data". Is there any way to do this with python and mechanize? Can I somehow convince me to mechanize that the form really has the meaning that I want to represent?

+3
source share
1 answer

, ClientForm, , , .

, , :

xitem = ClientForm.Item(browser.form.find_control(name="field1"), 
        {'contents':'E', 'value':'E', 'label':'E'})

,

xitem = ClientForm.Item(browser.form.find_control(name="field2"),
        {'type':'radio', 'name':'field2', 'value':'X'})

, , , .

+7

Source: https://habr.com/ru/post/1715298/


All Articles