Santosh Sharma
Santosh Sharma

Reputation: 2248

How to setTimeout in mechanize ruby?

i want to use setTimeout in mechanize ruby for full page load.

i have try following. but didn't work

mech = Mechanize.new { |agent|
  agent.open_timeout   = 5
  agent.read_timeout   = 5
}

any idea?

Upvotes: 1

Views: 639

Answers (2)

pguardiario
pguardiario

Reputation: 54984

Apparently there's also an idle_timeout but I'm not sure what the difference is or if it really works:

mech.methods.grep /timeout=/
#=> [:idle_timeout=, :open_timeout=, :read_timeout=]

Upvotes: 1

GDP2
GDP2

Reputation: 2008

I'm guessing that you're trying to use the setTimeout method from JavaScript, but unfortunately, Mechanize doesn't understand JavaScript and can't really work with it (see this question for more info). The methods that you're using are separate from the setTimeout functionality in JavaScript. You might have success with something like this using Watir or something similar:

# this assumes that `browser' is a `Watir::Browser' object
browser.execute_script("window.setTimeout(my_code, 2000)")

Upvotes: 1

Related Questions