Skip to content

Instantly share code, notes, and snippets.

@danilobellini
Created July 2, 2013 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danilobellini/5907591 to your computer and use it in GitHub Desktop.
Save danilobellini/5907591 to your computer and use it in GitHub Desktop.
Simple Splinter example with both XPath and CSS
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created on Tue Jul 2 05:17:13 2013
# @author: Danilo de Jesus da Silva Bellini
# Simple Splinter example with both XPath and CSS
from splinter import Browser
from tempfile import NamedTemporaryFile
data = """
<html><head><title>Splinter testing</title></head><body>
<select id="estado" name="estado">
<option value="teste1">teste1</option>
<option value="teste2">teste2</option>
<option value="teste3">teste3</option>
<option value="teste4">teste4</option>
</select>
</body></html>
"""
with Browser() as br:
with NamedTemporaryFile() as f:
f.write(data)
f.flush()
br.visit("file://" + f.name)
xpath_options = br.find_by_xpath("//option")
css_options = br.find_by_css("option")
print(xpath_options[2])
print(css_options[2])
print(len(xpath_options))
print(len(css_options))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment