6

I am trying to create a basic recording tool using Selenium2/Webdriver and I am aware that Selenium Already provides an IDE, but I want to build a more generic one.

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?

I appreciate your help.

Rex
  • 91
  • 1
  • 7

3 Answers3

5

I'm not familiar with the listeners. I know that people have tended to use something like BrowserMob Proxy to 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

Dave Haeffner
  • 314
  • 2
  • 4
  • Thank you so much for the precise response. It is actually exactly what I am looking for. Don't have enough reputation to vote for your answer :) – Rex May 30 '13 at 18:29
  • 1
    Also a link to Google group post and more detail description of the problem. https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/29GyTVvayCE – Rex May 30 '13 at 18:33
  • 1
    That's great to hear! Glad I was helpful and thanks for the props. – Dave Haeffner Jun 04 '13 at 02:18
  • Hi @rex, request you to share any implementation ideas on the same. Thanks. – Zeeshan S. Feb 21 '15 at 20:06
  • @Rex do you have any example code to share which can be used to listen to user actions on web? – bpk Oct 30 '15 at 15:50
  • 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 ;-) – David Feb 19 '17 at 09:14
  • Capturing API request and response will not going to serve the purpose here.....as @Rex wants to capture the user events in the browser. One have to use javascript to capture user events and element on which the action is being performed. – Rohit Aug 11 '17 at 06:44
  • Sorry for the late response everyone. I don't have code to share on this topic. Generally speaking, javascript is the way to capture user events. We are working on a Chrome extension, I will provide updates as soon as I have something more concrete. – Rex Feb 06 '18 at 19:22
  • Hi @Rex, I am really interested in hearing the approach you are using to achieve recording. Any updates? – Hamza Shahid Ali Nov 21 '19 at 16:08
1

There is indeed a WebDriverEventListener .See the doc link. Cheers.

HRVHackers
  • 2,793
  • 4
  • 36
  • 38
  • Thanks for the response. However, this listener works the opposite way. Meaning, when the web driver does a click a captures the event not vice versa. I would like to capture the events that happen in the browser such as click, drag-n-drop, send keys etc. in Java code. Similar to what Selenium IDE does but programmaticly. – Rex May 29 '14 at 11:24
-1

i had idea. that we clound use selemius to execution js code. look like ff.execute_script("alert('hello,selenium')") you can edit js to you want like onclick or onmove....

Nic3500
  • 8,144
  • 10
  • 29
  • 40