java组织。openqa。硒。遥远的UnreachableBrowserException如何定义EXE路径?
我在ChromeBrowser包中有这个java类代码(我制作的)
package ChromeBrowser;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchChrome{
public static void main(String[] args){
String url = "<<<The URL I want to open>>>";
WebDriver driver = setUp();
launch(driver, url);
}
static void launch(WebDriver driver, String url) {
driver.navigate().to(url);
}
static WebDriver setUp() {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
return driver;
}
}
但当我运行它时,我得到了一个错误:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
我已经采取了以下步骤:
预期结果:
我需要在C:\Program Files(x86)\Google\chrome\Application中定义chrome可执行文件的路径吗
请帮帮我,提前谢谢
EDIT::我尝试过其他大多数以错误名称命名的堆栈溢出问题,但都没有帮助
# 1 楼答案
似乎在使用Firefox创建会话时存在一些问题。尝试以下代码并使用Chrome浏览器进行测试
您需要从以下位置下载可执行驱动程序:https://sites.google.com/a/chromium.org/chromedriver/downloads
或者检查网络设置(代理、防火墙、防病毒软件),有东西被阻止了 selenium和浏览器之间的连接
# 2 楼答案
我不确定问题是什么,但你可以尝试以下建议-