Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "The type is deprecated" as an error in Selenium?

I am using eclipse-jee-luna-SR1-win32-x86_64 for Selenium (the Selenium version is selenium-standalone-2.44.0 and selenium-java-2.44.0). I am getting the error The type is deprecated. I have JavaSE-1.8 installed on my system.

> java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

This is the code I'm using:

import com.thoughtworks.selenium.DefaultSelenium; 
import com.thoughtworks.selenium.Selenium;
public class FirstTestCase {
    public static void main(String[] args) {
        System.out.println("Hello World");
        Selenium selenium = new DefaultSelenium("localhost", 5555, "chrome", "http://www.xxxxxxyxyxyx.com");
        }
}
like image 692
Abhinav Avatar asked Feb 11 '23 06:02

Abhinav


2 Answers

The Selenium Interface and DefaultSelenium Class both belong to Selenium 1 and are deprecated. Selenium has advanced to Selenium 2 (WebDriver) and for this reason these warning messages are displayed to encourage users to stop using old Selenium 1 code and start using Selenium 2 (WebDriver) code.

To add: This has got nothing to do with your IDE (Eclipse) or your Java version.

You will want to use the following classes as these are part of Selenium 2 (WebDriver). WebDriver is an interface used by various Selenium 2 drivers.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

Then you have various drivers that you can use. RemoteWebDriver / HtmlUnitDriver / FireFoxDriver / ChromeDriver / IEDriverServer etc. You will want to import the driver in your Java class.

Selenium selenium = new DefaultSelenium();

Becomes

WebDriver driver = new TheSpecificDriver();
like image 88
Paul Avatar answered Feb 13 '23 21:02

Paul


According to this selenium mirror on github

You should migrate to using WebDriver.

Just enhancing my answer, you might find this tutorial helpful https://code.google.com/p/selenium/wiki/GettingStarted

like image 33
csrcordeiro Avatar answered Feb 13 '23 20:02

csrcordeiro