当前位置: 首页 > 面试题库 >

Java Selenium Webdriver连接被拒绝

章兴发
2023-03-14
问题内容

我的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个


问题答案:

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



 类似资料:
  • 问题内容: 我是 HBase 和 Hadoop的 新手。我已经完全设置了HBase并完美启动。现在,当我尝试使用Java客户端从 p1 连接到HBase(HBase安装在 p2上 )时,它抛出了一个奇怪的异常。 问题答案: 我找到了解决方案。 通过仅从我的 主机中 删除 localhost 条目。现在我的本地主机条目就像 192.169.19.50 [这是我的hbase IP] =本地主机,而不是

  • 问题内容: 我正在尝试实现TCP连接,从服务器端一切正常,但是当我运行客户端程序(从客户端计算机)时,出现以下错误: 我尝试更改套接字号以防万一,但无济于事,有谁知道导致此错误的原因和解决方法。 服务器代码: 客户代码: 问题答案: 此异常意味着你尝试连接的IP /端口上没有侦听服务: 你试图连接到错误的IP /主机或端口。 你尚未启动服务器。 你的服务器没有监听连接。 在Windows服务器上,

  • 我无法连接到RabbitMQ。RabbitMQ不在本地计算机上。 我的应用程序.属性看起来像 我可以使用https://urltologinscreen:15671访问Rabbitmq gui 我得到以下错误 如何解决问题?

  • 我试着让我的selenium测试在debian服务器上运行,但是我一直从我的GeckoDriver得到连接拒绝错误。在运行Ubuntu的本地机器上,它运行得很好。你们谁知道怎么了?我找不到任何有用的东西。 OS:Debian Jessie 构建工具:Gradle Java-版本:8 设置方法 错误信息

  • 我试图通过Jedis客户端连接到redis服务器,但在连接时我得到了以下异常和堆栈跟踪- redisconnectionFailureException:无法获得Jedis连接;嵌套异常是redis.clients.jedis.exceptions.jedisconnectionException:无法从位于org.springframework.data.redis.connection.jed

  • 我正在尝试运行卡桑德拉,但每次它在连接时都会给出相同的错误...有什么我需要在配置文件或属性文件中编辑的吗? ('无法连接到任何服务器',{'127.0.0.1:9042 ':错误(61,"尝试连接到[('127.0.0.1 ',9042)]。最后一个错误:连接被拒绝")}) 启动cassandra时出错

  • 试图在localhost中建立从app容器到mysql容器的连接,出现连接拒绝异常 我们正在采取一种docker的方法来调用rest api服务来采用微服务的方法。我们正在建立应用程序容器和mysql容器之间的连接,同时我们编写了一个docker-compose文件,创建了mysql容器和应用程序容器,为这两个容器公开了端口。下面是运行docker-compose文件docker-compose

  • 问题内容: 我已经为RMI的客户端编写了以下代码。但是得到 代码: 问题答案: 如果要在绑定,重新绑定或查找时获取该注册表,则注册表不会运行。如果让它进行远程调用,请参阅Javadoc随附的RMI FAQ 中的项目A.1 ,如果您正在运行Linux,还请检查/ etc / hosts文件是否将127.0.0.1映射到localhost和您的真实IP地址。到您的真实主机名- 在某些Linux发行版中