Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20



Export Selenium IDE Script to other Languages

When recording test case with Selenium IDE, the default script will be html script. The script can be exported to other programming languages, so that QA engineers can use Java, C#, Ruby, or Python to develop Selenium test framework.


To change the script format, open "Options" menu, select "Format" command, and then choose one of these programming languages from the menu.


For example, you select Java/JUnit4/Webdriver, Selenium IDE will display a warning. Just click Ok.

The "source" will be converted to Java/JUnit4/WebDriver Code. You can copy the code into Java development console like Eclipse or Intellj, modify some code and then execute it as JUnit test.

Below is the code after importing it into Eclipse as JUnit test.

package com.seleniummaster.logintest;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SeleniumMasterLoginTest {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

  public void testSeleniumMasterLogin() throws Exception {
    driver.get(baseUrl + "/seleniummastertestapp/index.php");
    for (int second = 0;; second++) {
      if (second >= 60fail("timeout");
      try if (isElementPresent(By.cssSelector("img[alt=\"Selenium Master\"]"))) breakcatch (Exception e) {}

    assertEquals("Online users", driver.findElement(By.cssSelector("#sb-onlineusers > h3")).getText());

  public void tearDown() throws Exception {
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {

  private boolean isElementPresent(By by) {
    try {
      return true;
    catch (NoSuchElementException e) {
      return false;

  private boolean isAlertPresent() {
    try {
      return true;
    catch (NoAlertPresentException e) {
      return false;

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
      else {
      return alertText;
    finally {
      acceptNextAlert = true;