gpt4 book ai didi

java - 我已经安装了 Gecko 驱动程序,但仍然出现错误

转载 作者:行者123 更新时间:2023-12-02 02:01:12 25 4
gpt4 key购买 nike

我安装了 Gecko 驱动程序,因为我收到此错误:“java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;”

但是应用代码后我仍然收到 Gecko 驱动程序错误。

下面是我的完整代码。请让我知道我缺少什么。

public class Pawan {

public static WebDriver driver;

public static void main(String[] args){

System.setProperty("webdriver.firefox.marionette","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");

driver = new FirefoxDriver();

}

@Test
public void test() {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/");
driver.findElement(By.linkText("Find a Physician")).click();
driver.findElement(By.id("searchZip")).sendKeys("32806");
driver.findElement(By.linkText("Mile Radius")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}

driver.findElement(By.linkText("20")).click();
driver.findElement(By.linkText("Specialty")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.linkText("Anesthesiology")).click();
driver.findElement(By.cssSelector("input[type='submit'][value='Search Now']")).click();
String str= driver.findElement(By.xpath(".//*[@id='finderListView']/div[3]/div[1]/div/div[1]/p")).getText();

if("Anesthesiology".equals(str))

System.out.println("Physician Search Successful");
else
System.out.println("Physician Search NOT Successful");

driver.findElement(By.linkText("Browse Locations")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.xpath(".//*[@id='sidebarMenu']/div[1]/form/div/input")).sendKeys("32806");
driver.findElement(By.xpath(".//*[@id='sidebarMenu']/div[1]/form/input")).click();

try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.xpath(".//*[@id='sidebarMenu']/div[2]/section/div/ul/li[1]/a")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
WebElement divElement = driver.findElement(By.xpath(".//*[@id='overflow-autoScroll']/li[1]/ul/li/a/div[2]/span[3]"));
String stri = divElement.getText();
if(stri.contains("32806"))

System.out.println("Location Search successful");
else
System.out.println("Location Search not successful");

driver.findElement(By.xpath("html/body/header/div[1]/div[2]/a[3]")).click();

driver.findElement(By.linkText("Health Topics")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}

driver.findElement(By.linkText("Diabetes")).click();
WebElement divElementtwo = driver.findElement(By.xpath("html/body/div[4]/div/div[1]/div[1]/h2"));
String strn = divElementtwo.getText();
if(strn.contains("Diabetes"))
System.out.println("Blog Search successful");
else
System.out.println("Blog Search not successful");



}
}

最佳答案

要验证 gecko 驱动程序是否与您当前的 Firefox 和 selenium 版本兼容,请执行以下操作:

如果您使用的是 Windows 操作系统,请将下载的 gecko 驱动程序保存在 System32 位置;如果您使用的是 Mac OSX,请将下载的 gecko 驱动程序保存在 /usr/local/bin 位置

  1. 通过以下命令运行 Selenium Standalone 服务器:java -jar selenium-server-standalone-3.13.0.jar
  2. 在 Firefox 浏览器中打开此网址:http://localhost:4444/wd/hub
  3. 创建 session 并选择 Firefox 浏览器

如果浏览器启动,则 geckodriver 与 Firefox 和 Selenium 版本的兼容性没有问题。

关于java - 我已经安装了 Gecko 驱动程序,但仍然出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51542525/

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