WebDriverEventListener for EventFiringWebDriver. Similiarly what listener exists for Actions ?

576 views
Skip to first unread message

Krishnan Mahadevan

unread,
Aug 10, 2011, 9:01:31 AM8/10/11
to Selenium Users
I know we can listen to all webDriver originated events by coupling an EventFiringWebDriver and having it register to our own class which implements WebDriverEventListener.

so how do I listen to events that are being originated from Actions class ?

Is there a corresponding Listener for Actions as well ?


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Krishnan Mahadevan

unread,
Aug 10, 2011, 10:49:34 PM8/10/11
to Selenium Users
Any takers on this ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



Krishnan

unread,
Aug 24, 2012, 2:41:11 AM8/24/12
to seleniu...@googlegroups.com
Since I haven't seen any responses on this question, I am bumping it up with a working example which demonstrates that when Actions are used events are not getting fired. I am not sure completely if I am doing something wrong here, for which I would appreciate if someone can please clarify.

Question: Does EventFiringWebDriver capture events generated by "org.openqa.selenium.interactions.Actions".

Sample Code :

package raw.selenium;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.internal.WrapsElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.events.AbstractWebDriverEventListener;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class EventFiringWebDriverDemo {
private EventFiringWebDriver efd = null;

@Test
public void testMethod() {
WebElement element = efd.findElement(By.name("note"));
//The below 4 lines which relies on Action doesnot trigger events
Actions action = new Actions(efd.getWrappedDriver());
WrapsElement wrappedElement = (WrapsElement)element;
action.sendKeys(wrappedElement.getWrappedElement(), "Hello world").build().perform();
//However the below line which uses the regular way of clicking does work
element.sendKeys("Hello world");
}

@BeforeClass
public void beforeClass() throws MalformedURLException {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
URL url = new URL("http://localhost:4444/wd/hub");
RemoteWebDriver rwd = new RemoteWebDriver(url, dc);
efd = new EventFiringWebDriver(rwd);
efd.register(new MyEventListener());

}

@AfterClass
public void afterClass() {
efd.quit();

}

public static class MyEventListener extends AbstractWebDriverEventListener {
@Override
public void afterChangeValueOf(WebElement element, WebDriver driver) {
   super.afterChangeValueOf(element, driver);
System.out.println("afterChangeValueOf was invoked");
}
}
}


~Krishnan

Peter Gale

unread,
Aug 24, 2012, 3:50:12 AM8/24/12
to Selenium Users
Hi Krishnan

I've just started playing with EventFiringWebDriver myself, so I'm certainly no expert, but maybe I think I can confirm your thinking as being what I'd expect from my little experience.

Firstly, are you saying that when using actions, the events aren't getting fired in the browser, or just that the listener methods aren't getting fired by them?

If it's the former, then, it's obviously a WebDriver issue, but I'd be surprised it hasn't been picked up yet, so I suspect you don't mean that.
 
If it's the latter, as I suspect, I would expect you might have to register your listener class against the webdriver object performing the actions, like you seem to have said you are trying to do.

I can see you've done:

    efd.register(new MyEventListener());

but when you do:

   efd.getWrappedDriver()

I might expect you would need to do this:

    efd.getWrappedDriver().register(new MyEventListener());

... (or the equivalent) as well to get actions generated through this new driver object to trigger your event listener methods.

But there seems to me no .register() method for .getWrappedDriver().

I don't think I'm telling you anything new here, just claifying that I think I can see the same problem that you're getting at.

It certainly seems a reasonble question to ask the developers direct on the developers group, particularly as no one here seems to have come across the problem before and have an answer.

Hope that helps.


Peter

Date: Thu, 23 Aug 2012 23:41:11 -0700
From: krishnan.ma...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: WebDriverEventListener for EventFiringWebDriver. Similiarly what listener exists for Actions ?
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/S0YsPBU7Ou4J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Krishnan Mahadevan

unread,
Aug 24, 2012, 3:58:32 AM8/24/12
to seleniu...@googlegroups.com
Peter,

I am registering the EventListener and also using the WrappedDriver as well as the WrappedElement per recommendations from Jim Evans in this thread : https://groups.google.com/forum/#!msg/selenium-users/lJL2wF3kY04/qzpH6GR5xUcJ

My issue is that, when actions class performs operations such as click, sendkeys etc., these events are not being listened to by my WebDriverEventListener implementing class. This is my issue.

Sometime back I had come to a conclusion that EventFiringWebDriver and Actions/Select class DONOT go well together, but based on Jim's response, my hopes have revived :)

I plan on getting onto the Selenium chats perhaps sometime later today evening and get this clarified. Once I get a concrete reply, I will update this thread.

The getWrappedDriver() method when invoked on the EventFiringWebDriver pops out the actual WebDriver object to which it was bound to when it was instantiated. In my case it is a RemoteWebDriver and only EventFiringWebDriver class has the register() method. So the register method has to be invoked only on the EventFiringWebDriver instance and not on the wrapped driver object inside it.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Peter Gale

unread,
Aug 24, 2012, 4:06:09 AM8/24/12
to Selenium Users
It does sound like its either a bug or a missing step that's not well documented.

I guess I 'd encounter the same problem if ever I start to use actions, so it would be good to know if you get it working, thanks. I'll keep an eye out for your update.


Date: Fri, 24 Aug 2012 13:28:32 +0530
Subject: Re: [selenium-users] Re: WebDriverEventListener for EventFiringWebDriver. Similiarly what listener exists for Actions ?
From: krishnan.ma...@gmail.com
To: seleniu...@googlegroups.com

Jim Evans

unread,
Aug 24, 2012, 5:44:41 AM8/24/12
to seleniu...@googlegroups.com
To be fair, the issue I was addressing in that other thread was that you couldn't directly pass an instance of the .NET EventFiringWebDriver to the.NET Actions class. I have since made a change to the .NET bindings that will rectify this. I believe the Java bindings will still suffer the same issue until a corresponding change is made to them.

Furthermore, the .NET bindings do not raise any events from the Actions class. I'm reasonably sure that the Java bindings won't either, though I've not researched it thoroughly.

I've always considered the .NET versions the Support classes as nifty utilities to demonstrate what is possible to do with the library. If they work as-is, great; if not, the source code is there for inspection and modification. Note that I'm only speaking for .NET here, the maintainers of the Java bindings likely feel differently.

Krishnan Mahadevan

unread,
Aug 24, 2012, 7:23:57 AM8/24/12
to seleniu...@googlegroups.com
Jim,
Thanks for responding back. Yes you are correct. The Java bindings also are not raising any events from the Actions class.
So that kind of wraps up this thread that currently there is no listener support that dwells within the Java bindings, which would help a user to couple Actions class with a RemoteWebDriver instance and still get notified of events.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/88CnL-tAmkAJ.

Thejus Krishna

unread,
Oct 29, 2012, 1:39:13 PM10/29/12
to seleniu...@googlegroups.com
Hi All,

Today I was going through WebDriverEventListeners. Noticed that it can listen only events driven through Selenium and if we manually click or navigate in the browser, it doesn't catch that event.
Is that intended behavior or can we catch/record manual clicks on elements in browser after opening using Selenium?

Cheers,
Thejus
Reply all
Reply to author
Forward
0 new messages