Selenium脚本不工作异常

时间:2018-04-23 07:23:39

标签: selenium testing automation

我是selenium的初学者,需要一些帮助,下面的脚本我试图发送值vai文本字段。 以下是代码段。

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class login {
    static
    {
        System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
    }

    public static void main(String[] args) 
    {
        WebDriver driver=new ChromeDriver();
        driver.get("https://XXXXX.XXXXXX.com/authentication/login");

        driver.findElement(By.name("login")).sendKeys("ravi");

    }

}

显示错误

  

线程中的异常" main" java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;有关更多信息,请参阅https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver。最新版本可从http://chromedriver.storage.googleapis.com/index.html下载       在com.google.common.base.Preconditions.checkState(Preconditions.java:754)       在org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)       在org.openqa.selenium.chrome.ChromeDriverService.access $ 000(ChromeDriverService.java:32)       在org.openqa.selenium.chrome.ChromeDriverService $ Builder.findDefaultExecutable(ChromeDriverService.java:137)       在org.openqa.selenium.remote.service.DriverService $ Builder.build(DriverService.java:339)       在org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)       在org.openqa.selenium.chrome.ChromeDriver。(ChromeDriver.java:123)       在login.main(login.java:14)

1 个答案:

答案 0 :(得分:0)

试试这段代码:

public class login {

public static void main(String[] args) {
 System.setProperty("webdriver.chrome.driver","Path/to/your/chromedriver.exe");
 WebDriver driver=new ChromeDriver();
 WebDriver wait = new WebDriverWait(driver,30); 
 driver.get("https://XXXXX.XXXXXX.com/authentication/login");
 wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.name("login"))));
 driver.findElement(By.name("login")).sendKeys("ravi");