一尘不染

Java Selenium Webdriver连接被拒绝

selenium

我的seleniumwebdriver上出现了太常见的连接拒绝错误。几周前执行了相同的代码。

我一直在阅读现有帖子中的内容,并尝试将geckodriver和FireFox更新无济于事。我可以在另一台运行相同版本的驱动程序,浏览器和库等的计算机上运行相同的代码。如何找到特定于该计算机的原因?错误如下。

调试1调试2调试3

Exception in thread "main" org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:28379 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'LT9LTDRC2', ip: '10.130.3.15', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131' Driver info: driver.version: Gecko_Driver  
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91)  
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)     
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)    
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)    
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)  
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)     at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)     at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:137)     at seleniumPrograms.Gecko_Driver.main(Gecko_Driver.java:13) 
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:28379 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect   
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)  
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)    
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)    
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)   at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)   at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)  
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)   at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)    
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)     
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)     
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:139)  
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:87)   
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:343)   
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)   
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)     
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)  ... 8 more 
Caused by: java.net.ConnectException: Connection refused: connect   
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)  
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)   
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)    
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)     
at java.net.PlainSocketImpl.connect(Unknown Source)     
at java.net.SocksSocketImpl.connect(Unknown Source)     
at java.net.Socket.connect(Unknown Source)  
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)     
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)  ... 23 more

而且,即使是以下基本代码,我也可以运行它。

enter code here
package seleniumPrograms;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;

    public class Gecko_Driver {
        public static void main(String[] args)  {
             System.out.println("Debug 1");
             DesiredCapabilities capabilities=DesiredCapabilities.firefox();
             System.out.println("Debug 2");
             capabilities.setCapability("marionette", true);
             System.out.println("Debug 3");
             WebDriver driver = new FirefoxDriver(capabilities);
             System.out.println("Debug 4");
             driver.get("http://www.google.com");

             driver.manage().window().maximize();  
             driver.quit();
        }
 }

铬示例。

@Test
        public void testGoogleSearch() throws InterruptedException {
          // Optional, if not specified, WebDriver will search your path for chromedriver.
          System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");

          WebDriver driver = new ChromeDriver();
          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();
        }

故障跟踪:

org.openqa.selenium.WebDriverException:等待驱动程序服务器启动时超时。内部版本信息:版本:’未知’,版本:’未知’,时间:’未知’系统信息:主机:’LT9LTDRC2’,ip:‘192.168.1.6’,操作系统名称:’Windows
10’,os.arch: ‘amd64’,os.version:‘10
.0',java.version:'1.8.0_131'驱动程序信息:driver.version:org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)上的Gecko_Driver在org.openqa.selenium.remote.org.org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)的org.openqa.selenium.remote.service.DriverService.start(DriverService.java:181)
org.openqa.selenium.remote.RemoteWebDriver上的.RemoteWebDriver.execute(RemoteWebDriver.java:637)。[http://
localhost:31675 /
status]](http://localhost:31675/status])将在20002毫秒后在org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(.org.openqa.selenium.remote.service.DriverService.waitUntilAvailable((
DriverService.java:190)…
33更多原因:com.google.common.util.concurrent.UncheckedTimeoutException:com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter)上的java.util.concurrent.TimeoutException。
java:140)at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:80)…
34更多原因:java.util.concurrent.FutureTask.get处的java.util.concurrent.TimeoutException来源)com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:128)…另外35个


阅读 1032

收藏
2020-06-26

共1个答案

一尘不染

我们的安全部门引入了一项策略,该策略阻止了对geckodriver.exe执行的访问。这是通过尝试从cmd运行确定的。不知道为什么我在IDE中没有得到壁虎的有意义的错误(受组策略阻止),我在chrome和IE中却收到了此错误。为了使用驱动程序,需要将其保存在程序文件中,尽管这可能是我的特定情况。如果您遇到Geckodriver的错误,建议您尝试从cmd执行该错误,以查看是否存在策略问题。

2020-06-26