简单selenium脚本中的java错误
在使用它当时执行的同一chromedriver路径之前的一天,我尝试过使用同一种脚本,但今天,当我尝试使用另一种脚本时,我得到了错误
package ScriptsSelenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TextBox_EntData {
public static void main(String[] args){
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver","C:\\Users\\Sneha\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver.get("http://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("XXX@YYail.com");
driver.findElement(By.id("Passwd")).sendKeys("XXXXXX");
driver.findElement(By.id("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 http://code.google.com/p/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:197)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:110)
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:118)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:291)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:82)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:117)
at ScriptsSelenium.TextBox_EntData.main(TextBox_EntData.java:10)
# 1 楼答案
代码中唯一需要更改的是
chromedriver.exe
path语句的执行。在启动新的chromedriver
之前,需要调用它。 换衣服# 2 楼答案
检查一下你有没有铬驱动。exe文件,并使用以下Chrome配置
DesiredCapabilities
和ChromeOptions
类基本上允许您为浏览器设置一些选项(比如启动最大化浏览器、设置chromedriver路径等等)