Source

punkybrowster.work / examples / form_manipulation.py

from punky import Browster

browser = Browster()
browser.create_webview(show=True)

browser.load('form_manipulation.html')

# Note that the fill() method knows how to deal with unicode strings.
browser.fill('input[name="title"]', u'I must not fear (\u6211\u4e0d\u8bb8\u6015)')

browser.fill('textarea[name=message]', u'Fear is the mind killer (\u5bb3\u6015\u662f\u601d\u60f3\u7684\u6740\u624b)')

# Select the third option in the select widget:
browser.select('select[name=produce] option:nth-child(3)')

# Quotes in CSS selectors are usually optional but become necessary when dealing
# with numbers
browser.select('select[name=monkeys] option[value="12"]')
browser.select('select[name=monkeys] option[value="14"]')
browser.select('select[name=monkeys] option[value="15"]')

# Choose the third radio button:
browser.choose('input[name=show][value=golden]')

# Check the checkbox:
browser.check('input[name=intoxicated]')

# Uncheck the checkbox:
browser.uncheck('input[name=medicated]')

# Click the submit button:
browser.click('input[type=submit]')