英文:
Selenium Project : Errors in Eclipse
问题
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: 驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;更多信息,请参见https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver。可以从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)
英文:
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();
		
	}
}
getting this error:
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)
答案1
得分: 1
- 你导入了错误的包:
只需将 import openqa.selenium.By; 替换为 import org.openqa.selenium.By; 
英文:
- You are importing wrong package:
Just replace import openqa.selenium.By; with import org.openqa.selenium.By; 
答案2
得分: 0
将您的代码中的import openqa.selenium.By;替换为import org.openqa.selenium.By;。
英文:
Replace your import openqa.selenium.By;
with
import org.openqa.selenium.By;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论