chrome Webdriver无法解析为eclipse和java的类型错误 [英] chrome Webdriver can't be resolved to a type error eclipse and java

查看:195
本文介绍了chrome Webdriver无法解析为eclipse和java的类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用chrome,java和selenium进行一些自动化项目,并且在导入chrome驱动程序时遇到问题。

Im trying to do some automation projects with chrome, java and selenium and having problems importing the chrome driver.

package main;

import org.openqa.selenium.*;

public class SitePoster {

    public static void main(String[] args) {
         //System.setProperty("webdriver.chrome.driver", "./pathtodriver");
        WebDriver driver = new ChromeDriver();
        //Getting error saying "ChromeDriver can't be resolved to a type"
    } 

}


推荐答案

错误说明了一切:

"ChromeDriver can't be resolved to a type"

使用 Selenium时3.x 您必须通过 System.setProperty()行提及键值对,如下所示:

While working with Selenium 3.x you have to mention the Key-Value pair through System.setProperty() line mandatory as follows :

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

此外,根据最佳做法而不是 import org.openqa.selenium。 *; 您必须提及导入的各个包,如下所示:

Additionally, as per best practices instead of import org.openqa.selenium.*; you have to mention the individual packages for import as follows :

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver; 

这篇关于chrome Webdriver无法解析为eclipse和java的类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆