Is there a listener to capture user actions in the browser session launched by WebDriver

2,946 views
Skip to first unread message

Rex

unread,
May 25, 2013, 1:23:32 AM5/25/13
to seleniu...@googlegroups.com

More specifically, once I launch the browser using WebDiver API in java, I would like to register a listener with the current session so I can capture user interaction with the WebDriver's launched browser. Basically if I were to write record user interactions in Java, how can I do it?  Very similar to EventFiringWebDriver class, but this class notifies the listener when the driver initiates the command and not the borwser session. 

For example say I launch a browser with the following commands: 

WebDriver  driver = new FirefoxDriver();

Now there is a blank firefox browser open which says WebDriver on the bottom in red color. Now suppose I type www.google.com in this browser and press enter. The browser navigates me to google.com. Can I register a listener that notifies me on events that occurs on this browser session? 

Rex

unread,
May 25, 2013, 1:31:19 AM5/25/13
to seleniu...@googlegroups.com
Your help is greatly appreciate it.  

Krishnan Mahadevan

unread,
May 25, 2013, 5:36:33 AM5/25/13
to seleniu...@googlegroups.com
The EventFiringWebDriver does exactly that because you instantiate it by passing a WebDriver instance to it. 

So anything that you do via the EventFiringWebDriver are in fact the user action events on a given browser instance. 
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0eb9d038-4b9c-4d76-ba0e-b8a38efc7568%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

Rex

unread,
May 25, 2013, 10:39:29 AM5/25/13
to seleniu...@googlegroups.com


On Saturday, May 25, 2013 1:23:32 AM UTC-4, Rex wrote:

Rex

unread,
May 25, 2013, 10:40:17 AM5/25/13
to seleniu...@googlegroups.com

EventFiringWebDriver  methods only gets called when you invoke a method on the driver instance and not on the launched browser. For example: 

WebDirver driver = new new FirefoxDriver();


WebDriverListener eventListener = new MyOwnImplementationOfWebDriverListener(driver);

EventFiringWebDriver eventDriver = new EventFiringWebDriver(driver);

eventDriver
.register(eventListener);
eventFiringWebDriver
.get("http://www.google.com");
WebElement elem = eventFiringWebDriver.findElement(By.name("q"));
elem
.click();

This code will invoke the methods on the listener. However, I would like the actual click or other interactions with the browser session invoke a 
method on the listener. The funny thing is that if I fire a blank WebDriver browser session and put the URl in the browser and press enter the 
methods beforeNavigateTo and afterNavigateTo of the listener get invoked. But after that clicking or entering text doesn't trigger any of the 
methods afterClickOn or afterChangeValueOf.

For simplicity, imagine you were to write a record & play tool, how would you capture the user interactions with the launched WebDriver browser session? 

Thanks for your help.


Rex

unread,
May 30, 2013, 2:32:22 PM5/30/13
to seleniu...@googlegroups.com
Thanks to Dave Haeffner for his response on Stackoverflow regarding this question. Here is the answer for others who might be interested and the original post on the website. 
Original Post

Answer: 

I'm not familiar with the listeners. I know that people have tended to use something like BrowserMob Proxyto act as a man-in-the-middle to capture and replay HTTP actions. Since WebDriver runs using the JSON Wire Protocol, I think this may be more suited for what you're looking for.

Also, Simon Stewart (the creator of WebDriver) has a detailed write-up on the philosophies and architecture of the Selenium WebDriver project. You can see that here.

Cheers, Dave H

spsman...@gmail.com

unread,
Feb 11, 2017, 6:59:43 PM2/11/17
to Selenium Users
Rex,

Is it possible for you to share the snippet of the event capture implementation or any link where this reference is?

Xiang Dong

unread,
Feb 13, 2017, 2:34:12 AM2/13/17
to seleniu...@googlegroups.com

I guess you want to capture the action which manually performed by the end user on the browser (opened by webdriver), the simple answer is not  easy. The manual action (click, input etc) will not trigger the listener in your test codes. Your code could be considered as a client and the browser will be server. They are single direction call from the client to the server.  


One way is you inject some javascript code to the browser (via web driver) and capture those actions and send it back to somewhere. It is a little complicated but actually works.


Best Regards,

--david




From: seleniu...@googlegroups.com <seleniu...@googlegroups.com> on behalf of spsman...@gmail.com <spsman...@gmail.com>
Sent: Sunday, February 12, 2017 7:59 AM
To: Selenium Users
Subject: Re: [selenium-users] Is there a listener to capture user actions in the browser session launched by WebDriver
 
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

David

unread,
Feb 19, 2017, 4:26:55 AM2/19/17
to Selenium Users
RE: what Rex mentioned regarding Dave' Haeffner's response on SO: The proxy method sounds like good solution. But if I'm not mistaken, there's no existing solution implementation for it, so those interested will have to build their own. It would simply be a parser that reads Wireshark or BMP capture files (HAR, PCAP dump) and decodes/translates the captured JSONWireProtocol requests & responses to the relevant WebDriver API commands in one's desired language. Worthy of a 3rd party open source project to share w/ community ;-)

And for what David Dong suggestions, more specifics would be like writing event handlers in Javascript like onclick, onmouseover, onchange, etc. and do something that could be used to generate playback functionality later. Examples of the latter could be HTTP POSTing (the data/action) back to a web/app server (or REST/web service) to record the action (to DB, file, etc.), or the JS code could append/log the actions to local storage (of browser), cookies, or to hidden DOM elements, or simply log to browser/error console. Then getting it for replay is simply extracting back out from console (log) or invoke JS command (in console) to dump out the info from local storage, cookies, or DOM element value/attribute at end of recording session. For the post to web server option, no need to do something at end of record session other than send event to web server that the recording session has ended (for it to generate the action replay log/file), as each action is posted to the server as it happens unless you design it differently to do a single post to server at end of session with all the actions (stored locally first).

Both techniques are not that hard in theory to implement, but will take quite some amount of work to build. One requires good knowledge of REST, JSONWireProtocol, and parsing HAR files or PCAP dumps. The other requires good javascript knowledge.

Be cool if/when someone has working solution they could share with the community ;-)

Diana Alazzam

unread,
Mar 6, 2024, 5:04:44 AM3/6/24
to Selenium Users
Hello
I'm trying to do the same thing that you described but I was thinking that the script that we inject to the browser will not be persisted when user open new pages or tabs.
So we will not be able to log user events. Do you know how can we keep the injected script for the entire session?

Reply all
Reply to author
Forward
0 new messages