Skip to content

Instantly share code, notes, and snippets.

@oubiwann
Created October 14, 2012 01:56
Show Gist options
  • Select an option

  • Save oubiwann/3886983 to your computer and use it in GitHub Desktop.

Select an option

Save oubiwann/3886983 to your computer and use it in GitHub Desktop.
zope.testbrowser: Automating the Web
>>> from zope.testbrowser.browser import Browser
>>> b = Browser('http://google.com')
>>> b.title
'Google'
>>> b.getLink('About Google')
<Link text='About Google' url='http://www.google.com/intl/en/about.html'>
>>> b.getLink('About Google').click()
>>> b.title
'About Google'
>>> b.getLink('Investor Relations').click()
>>> b.title
'Google Investor Relations'
>>> b.getLink('Guidelines').click()
>>> 'Corporate Governance' in b.contents
True
>>> b = Browser('https://launchpad.net/+login')
>>> b.title
'Log in or register with Launchpad'
>>> b.getControl(name='loginpage_email', index=0).value = username
>>> b.getControl(name='loginpage_password').value = passwd
>>> b.getControl(name='loginpage_submit_login').click()
>>> b.title
'Launchpad'
>>> 'Logged in as' in b.contents
True
>>> b.getLink('Duncan McGreggor').click()
>>> b.title
'Duncan McGreggor in Launchpad'
>>> b.getLink('http://www.advogato.org/person/oubiwann/')
<Link text='http://www.advogato.org/person/oubiwann/' url='http://www.advogato.org/person/oubiwann/'>
>>> b.getLink('Change details').click()
>>> b.getControl(name='field.homepage_content').value = 'blog: http://oubiwann.blogspot.com'
>>> b.getControl(name='field.actions.save').click()
>>> b.getLink('http://www.advogato.org/person/oubiwann/')
Traceback (most recent call last):
[snip]
mechanize._mechanize.LinkNotFoundError
>>> b.getLink('http://oubiwann.blogspot.com')
<Link text='http://oubiwann.blogspot.com' url='http://oubiwann.blogspot.com'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment