from splinter import Browser
with Browser() as browser:
url = "http://www.google.com"
browser.visit(url)
browser.fill('q', 'splinter - python acceptance testing for web applications')
button = browser.find_by_name('btnG')
button.click()
if browser.is_text_present('splinter.readthedocs.io'):
print("Yes, the official website was found!")
else:
print("No, it wasn't found... We need to improve our SEO techniques")
browser = Browser('chrome')
browser = Browser('firefox')
browser = Browser('zope.testbrowser')
browser.windows
browser.windows[0]
browser.windows["window_name"]
browser.windows.current
browser.windows.current = browser.windows[3]
window = browser.windows[0]
window.is_current
window.is_current = True
window.next
window.prev
window.close()
window.close_others()
browser.reload()
browser.back()
browser.forward()
browser.title
browser.html
browser.url
b = Browser(user_agent="Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)")
browser.find_by_css('h1')
browser.find_by_xpath('//h1')
browser.find_by_tag('h1')
browser.find_by_name('name')
browser.find_by_text('Hello World!')
browser.find_by_id('firstheader')
browser.find_by_value('query')
first_found = browser.find_by_name('name').first
last_found = browser.find_by_name('name').last
second_found = browser.find_by_name('name')[1]
browser.find_by_css('h1').first.value
browser.click_link_by_href('http://www.the_site.com/my_link')
browser.click_link_by_partial_href('my_link')
browser.click_link_by_text('my link')
browser.click_link_by_partial_text('part of link text')
browser.click_link_by_id('link_id')
browser.find_by_css('h1').first.visible
browser.find_by_css('.content').first.has_class('content')
browser.find_by_name('send').first.click()
browser.find_link_by_text('my link').first.click()
browser.find_by_tag('h1').mouse_over()
browser.find_by_tag('h1').mouse_out()
browser.find_by_tag('h1').click()
browser.find_by_tag('h1').double_click()
browser.find_by_tag('h1').right_click()
draggable = browser.find_by_tag('h1')
target = browser.find_by_css('.container')
draggable.drag_and_drop(target)
browser.fill('query', 'my name')
browser.attach_file('file', '/path/to/file/somefile.jpg')
browser.choose('some-radio', 'radio-value')
browser.check('some-check')
browser.uncheck('some-check')
browser.select('uf', 'rj')
browser.driver.save_screenshot('your_screenshot.png')
browser.type('type', 'typing text')
'''
If you pass the argument slowly=True to the type method you can interact with the page on every key pressed. Useful for
'''
for key in browser.type('type', 'typing slowly', slowly=True):
pass
browser.find_by_name('name').type('Steve Jobs', slowly=True)
browser.find_by_css('.city').fill('San Francisco')
browser.visit('http://cobrateam.info')
browser.status_code.is_success()
browser.status_code == 200
browser.status_code.code
browser.cookies.add({'whatever': 'and ever'})
browser.cookies.all()
browser.cookies.delete('mwahahahaha')
browser.cookies.delete('whatever', 'wherever')
browser.cookies.delete()
with browser.get_iframe('iframemodal') as iframe:
iframe.do_stuff()
alert = browser.get_alert()
alert.text
alert.accept()
alert.dismiss()
prompt = browser.get_alert()
prompt.text
prompt.fill_with('text')
prompt.accept()
prompt.dismiss()
with browser.get_alert() as alert:
alert.do_stuff()
browser.execute_script("$('body').empty()")
browser.evaluate_script("4+4") == 8
browser = Browser()
browser.visit('https://splinter.readthedocs.io/')
browser.is_text_present('splinter')
browser.is_text_present('splinter', wait_time=10)
browser.is_not_present('text not present')
browser.is_element_present_by_css('h1')
browser.is_element_present_by_xpath('//h1')
browser.is_element_present_by_tag('h1')
browser.is_element_present_by_name('name')
browser.is_element_present_by_text('Hello World!')
browser.is_element_not_present_by_id('firstheader')
browser.is_element_not_present_by_value('query')
browser.is_element_present_by_value('query', wait_time=10)