new to ruby, love the language. read programmatic programmers guide to
get started and i understand the basics of ruby language. im just
starting to learn gems, ive played with mysql, crypt, and now mechanize.
I have yet to write a successful program with any of the gems but im
hooked on mechanize. ok so here is what im trying to do…
i am a student in itt tech online course. to get credit for attendance i
have to send emails everyday through the webpage. so i thought “yesss!!!
i can write a program using mechanize to do this for me.”
First question: is that even possible?
next i can get to the webpage and can print the forms but dont know how
to fill it out to submit it. here is my code and what i see when
executed:
#THIS IS MY CODE
require ‘rubygems’
require ‘mechanize’
-ok so i see the form, but i dont know which one i would put my user
name and password into.
-Also i use firebug to see the names of the text-fields on the actual
web page and their “names” are not in the list of fields that are
printed out.
-so my next question is how do i fill out the username and password
fields and click the submit button to get to the next page? id like to
figure it out by myself but i have not been having much luck. any help
is appreciated thank you!
Your problem is that username and password fields are not inside form.
Open Firebug and inspect those fields and you will see that.
Instead don’t vorry where it is, just select field with name fblogincd
and fbpassword,
fill in with data, and click on input element with id sImage1. That’s
all.
Is your requirement strictly Mechanize? Mechanize is good for simpler
sites
without javascript. If you need javascript (you will need it, before or
later) then Capybara is better solution. I could write you simple script
in
Capybara to do this task.
thank you. i am going to try your suggestion. is copybara a gem? i will
look into that as well. i would appreciate a simple script but i would
like to see if i can figure it out myself first. i knew that the
username and password fields were not in the form but i didnt think i
could just fill it out if it wasnt there. i will try it and get back to
you. thanks again.
It’s ok, but I prefer google groups or better stackoverflow.com, because
this could be interesting to other people. But of course if you need
some
help you can contact me by email.
the “action” in the form = {action
“javascript:exit(’/online/valdoc/cliksIndep_prcsslogin’)”}
-which im assuming means i need javascript, which mechanize cant handle?
dave i tried your script,one i came up with was similar only without the
rescue, and it raises the rescue “Not on login page or expected fields
not found.”
so im guessing i need to use copybara, which i will research and post
after i figure it out. thank you guys for all the help so far
ok i need help with capybara. i keep finding pages with info about using
it with cucumber and sinatra and im not sure what any of that is. do i
need those for what im trying to do?
next i can get to the webpage and can print the forms but dont know how
form = page.forms.each do |form|
pp form
end
You could try this. I have not tested it as my mechanize is broken at
present.
agent = Mechanize.new
page = agent.get(‘http://www.distance-education.itt-tech.edu/’)
form = page.forms.first
begin
form.fblogincd = user
form. fbpassword = password
form.submit
rescue
pp page
raise “Not on login page or expected fields not found.”
end
I’ve always found Watir-Webdriver to be a very powerful tool if you want
complex browser automation. It’s particularly good with JavaScript as
well as you can write and execute your own JavaScript commands in the
page.
but when i got an error i figured it was because i didnt set it to a
variable.
right now im not sure but this is what i came up with so far. any input
would be appreciated thank you
oh man that is cool!!! i can actually see it bring up the page and fill
in the fields!!! im going to keep going with this and let you know how i
make out.