java 为什么我在 Selenium 中将“类型已弃用”作为错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27661196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:11:57  来源:igfitidea点击:

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

javaseleniumselenium-rc

提问by Abhinav

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.

我正在为 Selenium 使用 eclipse-jee-luna-SR1-win32-x86_64(Selenium 版本是 selenium-standalone-2.44.0 和 selenium-java-2.44.0)。我收到错误The type is deprecated。我的系统上安装了 JavaSE-1.8。

> 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");
        }
}

回答by Paul

The SeleniumInterface and DefaultSeleniumClass 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.

Selenium接口和DefaultSelenium类同属硒1和被弃用。Selenium 已经升级到 Selenium 2 (WebDriver),因此显示这些警告消息是为了鼓励用户停止使用旧的 Selenium 1 代码并开始使用 Selenium 2 (WebDriver) 代码。

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

添加:这与您的 IDE (Eclipse) 或 Java 版本无关。

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

您将需要使用以下类,因为它们是 Selenium 2 (WebDriver) 的一部分。WebDriver是各种 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/ IEDriverServeretc. You will want to importthe driver in your Java class.

然后你有各种可以使用的驱动程序。RemoteWebDriver/ HtmlUnitDriver/ FireFoxDriver/ ChromeDriver/IEDriverServer等你将要import在你的Java类驱动程序。

Selenium selenium = new DefaultSelenium();

Becomes

成为

WebDriver driver = new TheSpecificDriver();

回答by csrcordeiro

According to this selenium mirror on github

根据github上的这个硒镜像

You should migrate to using WebDriver.

您应该迁移到使用 WebDriver。

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

只是增强我的答案,您可能会发现本教程很有帮助https://code.google.com/p/selenium/wiki/GettingStarted

回答by MindBrain

 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.firefox.FirefoxDriver;

 public class FirstTestCase {
     public static void main(String[] args) {
         WebDriver driver = new FirefoxDriver();
         driver.navigate().to("http://seleniumsimplified.com");
         driver.close();    
 }

}

 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.firefox.FirefoxDriver;

 public class FirstTestCase {
     public static void main(String[] args) {
         WebDriver driver = new FirefoxDriver();
         driver.navigate().to("http://seleniumsimplified.com");
         driver.close();    
 }

}