gpt4 book ai didi

Selenium 脚本不工作异常

转载 作者:行者123 更新时间:2023-11-28 20:50:14 25 4
gpt4 key购买 nike

我是 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");

}

}

显示错误

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:754) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at login.main(login.java:14)

最佳答案

试试这段代码:

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");

关于Selenium 脚本不工作异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49975481/

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