【问题标题】:Selenium Project : Errors in EclipseSelenium 项目:Eclipse 中的错误
【发布时间】:2020-05-04 16:46:09
【问题描述】:
package edurekha;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver; 


import org.openqa.selenium.By;

public class Firstscript {

    public static void main(String[] args) throws InterruptedException{
        // TODO Auto-generated method stub
        System.setProperty(" webdriver.chrome.driver", "C:\\java n other software executables\\chromedriver_win32 (2)\\chromedriver.exe");
        WebDriver driver  = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://login.yahoo.com/");
        driver.findElement(By.xpath("//input[@id='login-username']")).sendKeys("xyz@yahoo.com");
        Thread.sleep(10000);
        driver.findElement(By.xpath("//input[@id='login-signin']")).click();

    }

}

收到此错误:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at edurekha.Firstscript.main(Firstscript.java:17)

【问题讨论】:

  • 进口中有这个吗?导入 org.openqa.selenium.By;
  • 尝试在内部处理异常,不要抛出它们,因为在 main 之后没有其他人可以捕获它们(tip)

标签: java eclipse selenium


【解决方案1】:

1) 您正在导入错误的包: 只需替换 import openqa.selenium.By;与导入 org.openqa.selenium.By;

【讨论】:

    【解决方案2】:

    替换您的import openqa.selenium.By;import org.openqa.selenium.By;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      相关资源
      最近更新 更多