Created
January 13, 2009 03:12
-
-
Save tenderlove/46304 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'johnson' | |
require 'rubygems' | |
require 'nokogiri' | |
doc = Nokogiri::HTML(<<-eohtml) | |
<html> | |
<head> | |
<script> | |
function populateForm() { | |
var select = document.getElementsByTagName("select").item(0); | |
var colors = ['red', 'green', 'blue']; | |
// Populate drop down | |
for(var i = 0; i < colors.length; i++) { | |
var color = colors[i]; | |
var option = document.createElement('option'); | |
var text = document.createTextNode(color); | |
option.appendChild(text); | |
option.setAttribute('value', color); | |
select.appendChild(option); | |
} | |
// Change the form action | |
var form = document.getElementsByTagName("form").item(0); | |
form.setAttribute('action', 'http://tenderlovemaking.com/'); | |
form.setAttribute('method', 'post'); | |
} | |
</script> | |
</head> | |
<body onload="populateForm()"> | |
<form> | |
<select id="select_tag" name="fave_color"> | |
</form> | |
</body> | |
</html> | |
eohtml | |
rt = Johnson::Runtime.new | |
rt['document'] = doc | |
rt.evaluate(doc.at('script').content) | |
rt.evaluate(doc.at('body')['onload']) | |
puts doc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment