Mario Stoilov Mario Stoilov - 1 year ago 71
Ruby Question

Execute code whenever page is navigated

I am looking for a way to detect whenever the current page is navigated in selenium so I can execute some code. I know in C# and Java there are events for this, but I cannot seem to find them in ruby. Can anyone point me in the right direction?

Answer Source

Here's an example, from the doc:

class NavigationListener < Selenium::WebDriver::Support::AbstractEventListener
  def initialize(log)
    @log = log

  def before_navigate_to(url, driver) "navigating to #{url}"

  def after_navigate_to(url, driver) "done navigating to #{url}"

listener =
driver = Selenium::WebDriver.for :firefox, :listener => listener

It's probably incomplete but it's a start.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download