WebDriver和ChromeDriver无法解析为类型

时间:2019-12-08 13:10:27

标签: java selenium google-chrome selenium-webdriver selenium-chromedriver

我知道这是一个非常常见的问题,但是我已经尝试了很多针对此问题的修复程序(包括:再次下载Java和eclipse),但所有修复程序均无效。 我要求提供非常具体且简化的帮助,因为我是这个主题的新手,并且我不太了解。

导入和chromedriver和webdriver出现错误。

这是代码:

package firstPackage;

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

public class FirstScript {

    public static void main(String[] args) {
        System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver");

        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");

    }

}

here is the project with all of the selenium jars that i downloaded from their site here is where the chromedrivere.exe file is stored

Output

4 个答案:

答案 0 :(得分:0)

您可以更改

System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver");

System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe"); 

答案 1 :(得分:0)

由于没有将硒依赖项添加到类路径中,因此出现错误。

我强烈建议您使用诸如Maven或Gradle之类的依赖项管理工具来做到这一点。

但是,如果您仍然想添加所有依赖项,则需要以下依赖项(您可以尝试仅使用chrome依赖项,然后尝试一下)

Resolved Dependencies

您还应该更改

type Obj1 struct {
    Title string `json:"title"`
    Views int    `json:"views"`
}

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrderDetailTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('blogPost', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title', 100);
            $table->dateTime('createdAt');
            $table->dateTime('updatedAt');
            $table->dateTime('deletedAt')->nullable();
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orderdetail');
    }
}

(有关财产的情况很重要)。

答案 2 :(得分:0)

应为System.setProperty(“ Webdriver.chrome.driver”,“ / C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe”);在setProperty()中。

还请添加所有必需的jar文件。

答案 3 :(得分:0)

此错误消息...

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type

...表示 WebDriver ChromeDriver 编译时未被解析。


您的imports似乎不错。但是,在使用操作系统时,您需要注意以下几点:

  • System.setProperty()行中,您需要将Webdriver.Chrome.driver替换为 webdriver.chrome.driver
  • 您需要提供 chromedriver 绝对路径,以删除初始的反斜杠,即 / C:之前。
  • 您还可以提供 chromedriver 绝对路径,以转义斜线表示,即 \\
  • 您需要提供 chromedriver 二进制文件的扩展名,即 exe
  • 因此,有效的代码行将是:

    System.setProperty("webdriver.chrome.driver","C\\Users\\shale\\Downloads\\chromedriver_win321\\chromedriver.exe");
    
  

您可以在java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests

中找到相关的讨论