Login to a website by using Ruby (urgent)

Hi
I am trying to create a monitoring script which will login to a website
and just get some result

i was testing "Mechanize"

and i was able to login webiste like "Wordpres"

but the page i am trying to login , its apax and using javascript : -

<form name="form1" method="post" action="Login.aspx"
onsubmit="javascript:return WebForm_OnSubmit();"
onkeypress="javascript:return WebForm_FireDefaultButton(event,
'btnLogin')" id="form1">

as i understand Mechanize does not work with javascript.

is there any other way to do this ??
Please help its bit urgent .,

···

--
Posted via http://www.ruby-forum.com/.

Usually for websites with JS I use Watir-Webdriver
http://watirwebdriver.com/

The above site has a few examples which should make writing a login
script easy.

···

--
Posted via http://www.ruby-forum.com/.

Hi Joel,
Thanks for this
I have download that one
but the firefox i am using , its quite old (i gues)

3.6.24-3.el6_1

and looks like Selenium::WebDriver does not work with that old version

So i have downloaded and unzip the new version of firefox, and trying to
use
path

require 'rubygems'
require 'watir-webdriver'
profile = Selenium::WebDriver::Firefox::Profile.new
profile = Selenium::WebDriver::Firefox::Binary.path='/tmp/firefox/'

b = Watir::Browser.new :firefox, :profile => profile

but it does not seem to work

how exactly you put the path ?

any help will be good .

also other then any browser, does not it work ??

···

--
Posted via http://www.ruby-forum.com/.

Well, you're overwriting "profile", so your first attempt at creating it
does nothing. Are you sure you need to specify the profile?

If you want to use your normal profile:
profile = Selenium::WebDriver::Firefox::Profile.from_name('default')

If you just want Firefox with a blank profile, then this should suffice
(on Ruby 1.9+):

require 'watir-webdriver'
b = Watir::Browser.new

···

--
Posted via http://www.ruby-forum.com/.

Hi,
I am quite new to concept.

I just download Chrome aswell

So both downloaded Crome and Firefox is under /root/fosiul directory
where the script is

So what will be syntax to make it work ??
Thanks for your help .

···

--
Posted via http://www.ruby-forum.com/.

also
i need to do this under proxy
so i thought, I need profile to assign proxy.

···

--
Posted via http://www.ruby-forum.com/.

also

ok with this setup

require 'rubygems'
require 'watir-webdriver'
profile = Selenium::WebDriver::Chrome::Profile.new

b = Watir::Browser.new :chrome, :switches =>
%w[--proxy-server=xx.xx.xx.xx:3128]

/usr/local/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/chrome/service.rb:50:in
`start': unable to connect to chromedriver http://127.0.0.1:9515
(Selenium::WebDriver::Error::WebDriverError)
        from
/usr/local/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/chrome/bridge.rb:15:in
`initialize'
        from
/usr/local/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/driver.rb:37:in
`new'
        from
/usr/local/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/driver.rb:37:in
`for'
        from
/usr/local/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver.rb:67:in
`for'
        from
/usr/local/lib/ruby/gems/2.1.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/browser.rb:46:in
`initialize'
        from testwaitir.rb:7:in `new'
        from testwaitir.rb:7:in `<main>'

···

--
Posted via http://www.ruby-forum.com/.

It's been a while since I used Chrome like that, but I recall that it
required a stand-alone exe as well as the gem.

I'd recommend getting Firefox to work with your proxy settings before
moving on to Chrome, since Firefox should be simpler.

To specify the Firefox installation to use, you need a command like
this:
Selenium::WebDriver::Firefox.path = "/root/fosiul/firefox.exe"

···

--
Posted via http://www.ruby-forum.com/.

Hi Joel

Thanks for the help so far ..

But still i cant understand what will be full code with proxy..

i am trying different combination , does not seems to work
Can you just help me with that

just a sample code by using Firefox ( path) + proxy .

example
if i use this, it does not work
profile =
Selenium::WebDriver::Firefox::Binary.path='/root/firefox'::Profile.new

b = Watir::Browser.new :firefox, :profile => profile

it does not work at all ..

Please advise ..

···

--
Posted via http://www.ruby-forum.com/.

Have you tried reading this?

http://watirwebdriver.com/firefox/

There is a specific example for using a proxy, which you don't appear to
be following.

···

--
Posted via http://www.ruby-forum.com/.

Hi yes

profile = Selenium::WebDriver::Firefox::Profile.new
profile.proxy = Selenium::WebDriver::Proxy.new :http =>
'myproxy.com:8080:, :ssl => 'myproxy.com:8080'
b = Watir::Browser.new :firefox, :profile => profile

but problem is : it does not take the Path options

path or binary path for manual firefox location...

this is the issues

···

--
Posted via http://www.ruby-forum.com/.

All you need to do is use
Selenium::WebDriver::Firefox.path = "/root/fosiul/firefox.exe"
before you start the browser.

The proxy config is independent of this setting.

···

--
Posted via http://www.ruby-forum.com/.

Looks like it's timing out trying to connect to Firefox.

Does it work without using a Proxy? (default)
Does it work without using the secondary Firefox installation? (default)
Is your Firefox version compatible with webdriver?
Does a Firefox window open when doing this?

···

--
Posted via http://www.ruby-forum.com/.

Ok just realized that
its works if i try to run the code from GUI interface!!
then its open Fiefox browser

but i am trying to use this from Terminal .

i have also install Xvfb

any help for terminal ??

···

--
Posted via http://www.ruby-forum.com/.

I don't know what you mean by GUI interface. I can't really help without
some meaningful information, such as the details I previously asked for.

If there's a difference between your GUI and your console code causing
one to work and other to fail, then that's where you need to look.

···

--
Posted via http://www.ruby-forum.com/.

Hi Sorry for confusion.

I am using Redhat ( linux)

So if i run the code from "Terminal" inside the Desktop (GNOME)

it bring up the firefox browser and open the site

but if i run the code from Remote location without GNOME ( Via SSh )

its fails as it does not find any display.

So what I am guessing is, some where i need to configure Display server
for this to work remotely.

Does it make sense ??

···

--
Posted via http://www.ruby-forum.com/.

If you aren't in a graphical environment you'll need a headless browser.

Alternatively you could have the task run within GNOME but be triggered
by a remote event or schedule, or use a remote-desktop type of
application like xlaunch

···

--
Posted via http://www.ruby-forum.com/.

Hi thanks
Thats what, i said in my previous post

i have installed Xvfb already , but still now luck ,

let me play with in further, i will come back
thanks

···

--
Posted via http://www.ruby-forum.com/.

Joel Pearson wrote in post #1132982:

All you need to do is use
Selenium::WebDriver::Firefox.path = "/root/fosiul/firefox.exe"
before you start the browser.

The proxy config is independent of this setting.

Hi ,
Sorry to be pain

i have downgraded to 1.9 to make sure its suitable but still i see this

ruby testwaitir.rb
/usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/firefox/launcher.rb:79:in
`connect_until_stable': unable to obtain stable firefox connection in 60
seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)

is not there any other way to do ??

···

--
Posted via http://www.ruby-forum.com/\.

If your working with a remote box then there's the headless gem which is a wrapper for Xvfb: GitHub - leonid-shevtsov/headless: Create a virtual X screen from Ruby, record videos and take screenshots.
and here's a watir example: Watirwebdriver.com

···

On 2014-01-15 12:06, Fosiul Alam wrote:

Hi Sorry for confusion.

I am using Redhat ( linux)

So if i run the code from "Terminal" inside the Desktop (GNOME)

it bring up the firefox browser and open the site

but if i run the code from Remote location without GNOME ( Via SSh )

its fails as it does not find any display.

So what I am guessing is, some where i need to configure Display server
for this to work remotely.

Does it make sense ??