gpt4 book ai didi

java - 无法使用 chrome 和 gecko 驱动程序执行 selenium java 程序

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

我计划使用 java 和 eclipse 使用 selenium 来自动化浏览器,但是当我尝试执行该程序时,它给了我异常“线程“main”中的异常 java.util.ServiceConfigurationError: org.openqa.selenium.remote.session .CapabilityFilter:模块 org.openqa.selenium.remote 未声明 uses"

下面是尝试执行的代码。

package com.sample;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
//comment the above line and uncomment below line to use Chrome
//import org.openqa.selenium.chrome.ChromeDriver;
public class Myclass {


public static void main(String[] args) {
// declaration and instantiation of objects/variables
//System.setProperty("webdriver.gecko.driver","D:\\Automation\\geckodriver.exe");
//WebDriver driver = new FirefoxDriver();
//comment the above 2 lines and uncomment below 2 lines to use Chrome
System.setProperty("webdriver.chrome.driver","D:\\Automation\\chromedriver.exe");
WebDriver driver = new ChromeDriver();


/*
* System.setProperty("webdriver.gecko.driver",
* "D:\\Automation\\geckodriver.exe"); DesiredCapabilities capabilities =
* DesiredCapabilities.firefox(); capabilities.setCapability("marionette",true);
* WebDriver driver= new FirefoxDriver(capabilities);
*/
String baseUrl = "http://demo.guru99.com/test/newtours/";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";

// launch Fire fox and direct it to the Base URL
driver.get(baseUrl);

// get the actual value of the title
actualTitle = driver.getTitle();

/*
* compare the actual title of the page with the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}

//close Fire fox
driver.close();

}

}

尝试使用 chromedriver 和 geckodriver,但两者都遇到相同的问题。请帮忙。

最佳答案

为了避免ResolutionException,您必须包含selenium jar,因为您的IDE无法检测到它。如果存在,请尝试从您的端删除外部 jar 。

完成此操作后,请尝试重新启动 IDE。

关于java - 无法使用 chrome 和 gecko 驱动程序执行 selenium java 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60913005/

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