[英]org.openqa.selenium.remote.UnreachableBrowserException How to define EXE path?
I have this java class code in package ChromeBrowser (That I made) 我在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;
}
}
But when I run it, I get the error: 但是当我运行它时,我得到了错误:
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.
Steps I've taken: 我已采取的步骤:
Expected result: 预期结果:
Do I need to define the path to the chrome executable at C:\\Program Files (x86)\\Google\\Chrome\\Application? 我是否需要在C:\\ Program Files(x86)\\ Google \\ Chrome \\ Application下定义chrome可执行文件的路径?
Help me please thanks in advance. 请帮助我,谢谢。
EDIT:: I've tried most of the other stack overflow questions with the name of the error, but they haven't helped. 编辑::我已经尝试了其他大多数使用错误名称的堆栈溢出问题,但它们并没有帮助。
I am not really sure what the issue is but you can try below suggestions- 我不太确定问题是什么,但是您可以尝试以下建议-
System.setProperty("webdriver.chrome.driver", "C:/Selenium/chromedriver.exe"); System.setProperty(“ webdriver.chrome.driver”,“ C:/Selenium/chromedriver.exe”);
This could be a compatibility issue between the 'selenium', 'Chrome browser version' and 'chrome driver' version that you are using. 这可能是您使用的“硒”,“ Chrome浏览器版本”和“ chrome驱动程序”版本之间的兼容性问题。 If you are using Selenium 2.53, then using chrome driver 2.25 should work for you. 如果您使用的是Selenium 2.53,则应使用chrome驱动程序2.25。
Download latest chrome driver from seleniumhq.org 从seleniumhq.org下载最新的Chrome驱动程序
Add 127.0.0.1 localhost to C:\\Windows\\System32\\drivers\\etc\\hosts. 将127.0.0.1本地主机添加到C:\\ Windows \\ System32 \\ drivers \\ etc \\ hosts。
Seems like there is some issue with creating session with Firefox. 似乎使用Firefox创建会话存在一些问题。 Try the following code and test using Chrome browser. 尝试以下代码,然后使用Chrome浏览器进行测试。
You need to download the executable driver from: https://sites.google.com/a/chromium.org/chromedriver/downloads 您需要从以下位置下载可执行驱动程序: https : //sites.google.com/a/chromium.org/chromedriver/downloads
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver",
"/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver = new ChromeDriver();
//Puts an Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch website
driver.get("http://www.calculator.net/");
//Maximize the browser
driver.manage().window().maximize();
or Check the network settings (proxy, firewall, antivirus software), something is blocking connections between selenium and the browser. 或检查网络设置(代理,防火墙,防病毒软件),发现某些东西阻止了硒与浏览器之间的连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.