Selenium 项目:Eclipse 中的错误

huangapple go评论133阅读模式
英文:

Selenium Project : Errors in Eclipse

问题

  1. package edurekha;
  2. import java.util.concurrent.TimeUnit;
  3. import org.openqa.selenium.WebDriver;
  4. import org.openqa.selenium.chrome.ChromeDriver;
  5. import org.openqa.selenium.By;
  6. public class Firstscript {
  7. public static void main(String[] args) throws InterruptedException{
  8. // TODO Auto-generated method stub
  9. System.setProperty("webdriver.chrome.driver", "C:\\java n other software executables\\chromedriver_win32 (2)\\chromedriver.exe");
  10. WebDriver driver = new ChromeDriver();
  11. driver.manage().window().maximize();
  12. driver.manage().deleteAllCookies();
  13. driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
  14. driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  15. driver.get("https://login.yahoo.com/");
  16. driver.findElement(By.xpath("//input[@id='login-username']")).sendKeys("xyz@yahoo.com");
  17. Thread.sleep(10000);
  18. driver.findElement(By.xpath("//input[@id='login-signin']")).click();
  19. }
  20. }

错误信息:

  1. Exception in thread "main" java.lang.IllegalStateException: 驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;更多信息,请参见https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver。可以从http://chromedriver.storage.googleapis.com/index.html下载最新版本
  2. at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
  3. at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
  4. at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
  5. at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
  6. at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
  7. at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
  8. at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
  9. at edurekha.Firstscript.main(Firstscript.java:17)
英文:
  1. package edurekha;
  2. import java.util.concurrent.TimeUnit;
  3. import org.openqa.selenium.WebDriver;
  4. import org.openqa.selenium.chrome.ChromeDriver;
  5. import org.openqa.selenium.By;
  6. public class Firstscript {
  7. public static void main(String[] args) throws InterruptedException{
  8. // TODO Auto-generated method stub
  9. System.setProperty(&quot; webdriver.chrome.driver&quot;, &quot;C:\\java n other software executables\\chromedriver_win32 (2)\\chromedriver.exe&quot;);
  10. WebDriver driver = new ChromeDriver();
  11. driver.manage().window().maximize();
  12. driver.manage().deleteAllCookies();
  13. driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
  14. driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  15. driver.get(&quot;https://login.yahoo.com/&quot;);
  16. driver.findElement(By.xpath(&quot;//input[@id=&#39;login-username&#39;]&quot;)).sendKeys(&quot;xyz@yahoo.com&quot;);
  17. Thread.sleep(10000);
  18. driver.findElement(By.xpath(&quot;//input[@id=&#39;login-signin&#39;]&quot;)).click();
  19. }
  20. }

getting this error:

  1. Exception in thread &quot;main&quot; 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
  2. at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
  3. at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
  4. at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
  5. at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
  6. at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
  7. at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
  8. at org.openqa.selenium.chrome.ChromeDriver.&lt;init&gt;(ChromeDriver.java:123)
  9. at edurekha.Firstscript.main(Firstscript.java:17)

答案1

得分: 1

  1. 你导入了错误的包:
    只需将 import openqa.selenium.By; 替换为 import org.openqa.selenium.By;
英文:
  1. 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;

huangapple
  • 本文由 发表于 2020年5月5日 00:46:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/61597343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定