gpt4 book ai didi

java - ChromeDriver 无法导航到 eclipse 中的 URL

转载 作者:行者123 更新时间:2023-11-30 02:59:28 25 4
gpt4 key购买 nike

我对 Cucumber 非常陌生,使用 ChromeDriver 请求 URL 时出现以下错误:

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:177)

我的代码:

package cucumber.features;

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

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class AddToList {

WebDriver driver = null;

@Given("^I am on Todo site$")
public void onSite() throws Throwable {
driver = new ChromeDriver();
driver.navigate().to("http://localhost");
System.out.println("on todo site");

}

@When("^Enter a task in todo textbox$")
public void enterTask() throws Throwable {
driver = new ChromeDriver();
driver.findElement(By.name("task")).sendKeys("Test Unit Using Cucumber");
;
System.out.println("task entered");
}

@Then("^I click on add to todo$")
public void clickAddToTodo() throws Throwable {
driver = new ChromeDriver();
driver.findElement(By.xpath("//input[@value='Add to Todo' and @type='button']"));
System.out.println("add button clicked");

}

}

最佳答案

我在使用 selenium 库时遇到了类似的问题。我在创建驱动程序之前发现了这一行并将其修复。

System.setProperty("webdriver.chrome.driver", PATH_TO_CHROME_DRIVER);

Here is simple project that could help you.

关于java - ChromeDriver 无法导航到 eclipse 中的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36316737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com