微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 为什么我在Selenium中将“类型被弃用”视为错误?

我正在使用eclipse-jee-luna-SR1-win32-x86_64用于Selenium(Selenium版本是selenium-standalone-2.44.0和selenium-java-2.44.0).我收到错误该类型已被弃用.我的系统上安装了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)

这是我正在使用的代码

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

解决方法:

Selenium接口和DefaultSelenium类都属于Selenium 1并且已弃用. Selenium已推进到Selenium 2(WebDriver),因此显示这些警告消息以鼓励用户停止使用旧的Selenium 1代码并开始使用Selenium 2(WebDriver)代码.

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

您将需要使用以下类,因为它们是Selenium 2(WebDriver)的一部分. WebDriver是各种Selenium 2驱动程序使用的接口.

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

然后你有各种各样的驱动程序,你可以使用. RemoteWebDriver / HtmlUnitDriver / FireFoxDriver / ChromeDriver / IEDriverServer等.您将要在java类中导入驱动程序.

Selenium selenium = new DefaultSelenium();

WebDriver driver = new TheSpecificDriver();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐