13

Is it possible to capture user input/actions with Selenium WebDriver, in the same way that you can use the Selenium IDE for recording / creating tests?

i.e. when the user enters a URL, clicks a link, fills in a text box, clicks a button etc etc.

I'd like to be able to capture these actions using the WebDriver rather than just using the Selenium IDE, as I want to integrate with other classes available in my Java application.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Dave
  • 656
  • 2
  • 6
  • 22
  • + favorites. In other news: I am not aware of this being possible – Pavel Janicek Nov 06 '12 at 14:51
  • You can only change the format in Selenium IDE during recording. By default, it is recorded in HTML format. You can change the format for java as Java / JUnit4 / WebDriver which will record in Java format for you. – Ripon Al Wasim Jul 29 '15 at 06:44

3 Answers3

4

I attempted to offer a viable solution in Record Actions using Selenium

Hope this helps.

Community
  • 1
  • 1
sep
  • 186
  • 1
  • 2
0

You can't 'record' a set of actions with Selenium WebDriver, you will need to write those steps manually.

Strictly speaking you can capture user input by using the WebDriver API in your chosen language (C#, Java, PHP, Ruby. Python, Perl or JavaScript) and it vaguely resembles using the DOM. If it suits your requirements you could use configuration files to supply some of your user input.

Navigate to a URL:

WebDriver driver = new FirefoxDriver();

driver.get('url')

Click a link/button:

WebElement element = driver.findElement(By.id("coolestWidgetEvah"));

element.click();

Enter Text in a field:

WebElement element = driver.findElement(By.id("coolestWidgetEvah"));

element.sendKeys('userinput');

For more information on the API Selenium HQ is pretty definitive:

http://seleniumhq.org/docs/03_webdriver.html#introducing-the-selenium-webdriver-api-by-example

If you're going from Selenium IDE to writing tests it'd be really useful to check out the page object pattern as I've found it makes your tests more maintainable in the long-run. This link is a good starting point because it gives an overview, and a visual representation of what you get by following the pattern:

http://blog.josephwilk.net/cucumber/page-object-pattern.html

Hope that helps.

NarendraR
  • 7,577
  • 10
  • 44
  • 82
Nickel
  • 533
  • 1
  • 7
  • 20
0

As far as I'm aware, there isn't an easy way to do it - but recording on IDE and exporting as a java file has worked well for me (File -> Export test case as...). I usually do it to c# but have used it with java.