我有一个 Google Chrome 55.0.2883.87 m
和 selenium.version 3.0.1
。
Chrome.exe
位于 C:\Program Files (x86)\Google\Chrome\Application
pom文件
<selenium.version>3.0.1</selenium.version>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
我运行代码
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.google.com/xhtml");
Thread.sleep(5000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
Thread.sleep(5000); // Let the user actually see something!
driver.quit();
并且有一个错误
Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 18032
Only local connections are allowed.
янв 10, 2017 12:18:56 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Starting ChromeDriver 2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed) on port 9515
Only local connections are allowed.
[0.003][SEVERE]: bind() returned an error: Only one usage of each socket address (protocol/network address/port) is normally permitted. (0x2740)
янв 10, 2017 12:19:56 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.NoSuchSessionException: no such session
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'EPRUMOSL15047', ip: '192.255.10.140', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=chrome not reachable
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 6.1.7601 SP1 x86_64), platform=ANY}]
Session ID: 3506210c8a0eb0d3b9abfdb238547455
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:322)
at utils.Main.main(Main.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Process finished with exit code 1
我也尝试过这些版本并收到错误
- 谷歌浏览器 55.0.2883.87 m 64 位
- 谷歌浏览器 54
- Google Chrome 53 x64 和 x86
- Google Chrome 51 x64 和 x86
请告诉我可能是什么原因?
最佳答案
当无法找到 Chrome 可执行文件时,我收到 NoSuchSessionException
;事实上 {message=chrome notreachable
似乎表明了这一点。
我的 Chrome exe 与您位于同一位置(C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
版本 55.0.2883.87 m
code>、ChromeDriver v2.25
、Selenium 3.0.1
,在 Windows 8.1 上),在我的情况下,无需指定其路径即可找到 exe(这是“默认路径”) location”,请参阅 here ),所以我希望在您的情况下也能找到它,但我的测试不使用 pom 文件或 Maven。
您可以尝试显式设置 Chrome 路径,如您所见 here 在非标准位置使用 Chrome 可执行文件,如果有任何因素可以排除可执行位置的原因。那将是:
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
ChromeDriver browser = new ChromeDriver(options);
关于java - Selenium chromedriver 2.27.440174 无法运行 Google Chrome 55.0.2883.87 m,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41565292/