簡體   English   中英

如何使用適用於 Chrome Windows 10 的 WebDriver 在 Eclipse (Java) 上安裝 Selenium

[英]How to Install Selenium on Eclipse (Java) with WebDriver for Chrome Windows 10

如何使用 WebDriver for Chrome 在 Windows10 上安裝 Selenium? 我沒有找到完整的教程,我不斷收到此錯誤:

在此處輸入圖片說明

Eclipse 中的這個異常:

Exception in thread "main" org.openqa.selenium.chrome.FatalChromeException: Cannot create chrome driver
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.chrome.ChromeCommandExecutor.start(ChromeCommandExecutor.java:382)
    at org.openqa.selenium.chrome.ChromeDriver.startClient(ChromeDriver.java:65)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:85)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:25)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:43)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:53)
    at Priority_Automation.MyAutomation.main(MyAutomation.java:18)

這是代碼:

import java.io.File;

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

public class MyAutomation {
    
    public static void main(String[] args)
    {
        //ChromeOptions options = new ChromeOptions();
        //options.addExtensions(new File("/path/to/extension.crx"));
        
        
        System.setProperty("webdriver.chrome.driver", 
  "C:\\Users\\user\\Desktop\\Selenuim\\chromedriver");
         ChromeDriver driver = new ChromeDriver();
        driver.get("www.google.com");
        System.out.println("Testing");
            
    }

}

請協助。

嗨@LiquidChild 請按照這個 Guru99 教程一步一步地安裝帶有 web 驅動程序的 selenium for chrome

鏈接https : //www.guru99.com/installing-selenium-webdriver.html

試試這個來自 Java T Point 的教程系列可以幫助你解決這個問題:

我看到在這4個鏈接中用一個例子解釋了所有的過程

由於您沒有看到任何編譯錯誤,因此在 Eclipse IDE 中安裝 Selenium 或在 Eclipse IDE 中配置 Selenium jar 似乎沒有問題。

然而,正如你在的內環境System.setProperty()行,你需要傳遞的絕對路徑ChromeDriver可執行包括擴展名即exe

如此有效,您的代碼行將是:

System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Desktop\\Selenuim\\chromedriver.exe");

此外,通過get()調用 url 您需要將完整的 url 傳遞為:

driver.get("https://www.google.com/");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM