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 : -

as i understand Mechanize does not work with javascript.

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

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.

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

the Error i get it

/usr/local/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/platform.rb:118:in
assert_file': not a file: "/tmp/firefox/" (Selenium::WebDriver::Error::WebDriverError) from /usr/local/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/platform.rb:123:inassert_executable’
from
/usr/local/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/firefox/binary.rb:101:in
`path=’

how exactly you put the path ?

any help will be good .

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

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 .

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

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

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:ininitialize’
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:infor’
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:ininitialize’
from testwaitir.rb:7:in new' from testwaitir.rb:7:in

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 …

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.

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.

http://code.google.com/p/selenium/wiki/ChromeDriver

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”

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 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

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?

Joel P. 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 ??

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.

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 ??

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

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 ??

If your working with a remote box then there’s the headless gem which
is a wrapper for Xvfb: https://github.com/leonid-shevtsov/headless
and here’s a watir example: http://watirwebdriver.com/headless/

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs