4

我对硒非常陌生,并试图在我的笔记本电脑中设置硒开始。我无法从我的简单代码中调用 IE。详情如下。你能帮我理解问题出在哪里吗

IE版本:IE 11,IE驱动:64位,操作系统:Windows 10 64位,Selenium版本:3.11

错误:

Started InternetExplorerDriver server (64-bit)
3.9.0.0
Listening on port 29313
Only local connections are allowed
Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:29313
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'DESKTOP-B1D1PSJ', ip: '192.168.79.96', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
	at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:223)
	at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:215)
	at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:152)
	at testing.Tryselenium.main(Tryselenium.java:31)
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:29313
	at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:240)
	at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:158)
	at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
	at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
	at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
	at okhttp3.RealCall.execute(RealCall.java:77)
	at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:101)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
	... 6 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 okhttp3.internal.platform.Platform.connectSocket(Platform.java:125)
	at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:238)

代码:

mport java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Tryselenium {
	  public static void main(String[] args) { 
	    // TODO Auto-generated method stub

		  WebDriver web;
		  /*System.setProperty("webdriver.chrome.driver","C:\\Users\\Divakar\\Documents\\General\\Learnings\\Selenium\\Others\\Set Up files\\Browser Drivers\\" + "chromedriver_x32.exe");
		  ChromeOptions chromeOptions = new ChromeOptions();
			chromeOptions.setExperimentalOption("excludeSwitches",Arrays.asList("test-type"));
			web = new ChromeDriver(chromeOptions);
			web.manage().window().maximize();
			web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);*/
			
		  System.setProperty("webdriver.ie.driver","E:\\General\\Learnings\\Selenium\\Others\\Set Up files\\Browser Drivers\\" + "IEDriverServer.exe");
			DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
	        capab.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
	        web = new InternetExplorerDriver();
	        web.manage().window().maximize();
	        web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);

		    /*FirefoxDriver web = new FirefoxDriver();			
	        web = new FirefoxDriver();	
	        web.manage().window().maximize();
	        web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);*/
	        
		web.get("http://www.icicibank.com/");
		web.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div/a[1]")).click();
		web.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div/div[3]/div/ul[1]/li[1]/a")).click();
	    web.findElement(By.xpath("/html/body/div[1]/div[2]/div[2]/div/div[1]/div/div[3]/a")).click();
	    web.findElement(By.name("AuthenticationFG.USER_PRINCIPAL")).sendKeys("507133118");
	    web.findElement(By.name("AuthenticationFG.ACCESS_CODE")).sendKeys("Soft2008");
	    web.findElement(By.name("Action.VALIDATE_CREDENTIALS")).click();
	    web.findElement(By.id("ContentLink1")).click();
	    

	    WebElement accttable =  web.findElement(By.xpath("/html/body/form/div/div[3]/div[1]/div[4]/div[2]/div/div/div[5]/div/div/div/div/div/div/div"));
		List<WebElement> all_rows =  accttable.findElements(By.tagName("tr"));
	    
		int j = 0;
		for (int i = 0; i < all_rows.size(); i++) {
	    	List<WebElement> rowAllCells = all_rows.get(i).findElements(By.tagName("td"));			
			if(rowAllCells.size()>1)
			{

				String acctno=rowAllCells.get(2).getText();
				if(rowAllCells.get(2).getText().trim().equalsIgnoreCase("602605049934"))
				{
					web.findElement(By.id("AccountSummaryFG.SELECTED_INDEX")).click(); ///html/body/form/div/div[3]/div[1]/div[4]/div[2]/div/div/div[5]/div/div/div/div/div/div/div/table/tbody/tr[4]/td[1]/input
					web.findElement(By.id("HREF_actNicNameOutput[" + j + "]")).click();
					web.findElement(By.id("backBtn")).click();
					web.findElement(By.id("VIEW_MINI_STATEMENT")).click();
					web.findElement(By.id("HREF_Logout")).click();
					web.close();
				}
				else 				j = j + 1;
			}
		}
	    
	    		
	    
	  }
	}

4

4 回答 4

4

错误说明了一切:

3.9.0.0
Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:29313
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'DESKTOP-B1D1PSJ', ip: '192.168.79.96', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver

从您的错误堆栈跟踪中可以清楚地看出,新会话没有被启动,并且driver.version也没有被识别。

您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:

  • 您正在使用Selenium Client v3.11.0
  • 您正在使用IEDriverServer v3.9.0.0
  • 您正在使用InternetExplorer v11.0(根据您的问题)

因此Selenium Client v3.11.0IEDriverServer v3.9.0.0之间存在明显的不匹配。

解决方案

  • 将IEDriverServer升级到 v3.11.1
  • 通过IDE清理项目工作区并仅使用所需的依赖项重建项目。
  • 使用CCleaner工具在执行测试套件之前和之后清除所有操作系统杂务。
  • 如果您的基础Web Browser基础版本太旧,请通过Revo Uninstaller将其卸载并安装最新的 GA 和已发布版本的Web Browser
  • 执行你的@Test.

其他注意事项

  • INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true您正在使用违反最佳实践的标志。不要这样做。
于 2018-03-15T11:03:24.920 回答
0

即使使用相同的驱动程序和客户端版本,我也会发生这种情况。

Started InternetExplorerDriver server (32-bit)
3.141.59.0
...
java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:XXXX
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'HOST_NAME', ip: 'XX.XXX.XX.XX', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251'
Driver info: driver.version: RemoteWebDriver

我最终在这里找到了完美的匹配

http://selenium-release.storage.googleapis.com/index.html

但是 IE 中的安全设置不同,并且在新计算机上不正确。使每个区域具有相同的启用保护模式框状态(每一个都选中或取消选中)

Internet Options -> Security

100% 修复它。正在让驱动程序启动并导航到页面,但前两个步骤修复了错误。

于 2020-06-29T22:41:50.967 回答
0

此答案已针对 Edge 浏览器进行了更新。如果您使用的是 Edge 浏览器并面临同样的问题。然后按照以下步骤操作:

  1. 从此位置下载最新的 IEDriverServer:https ://selenium.dev/downloads/

  2. 更新您的代码如下:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;

public class SL001_OpenWebpage_Edge 
    {
        public static void main(String[] args) 
        {       
            System.setProperty("webdriver.ie.driver", "\\location\\IEDriverServer.exe");

            WebDriver driver=new EdgeDriver();

            driver.get("https://www.hul.co.in/");

            driver.findElement(By.id("tcm:1255-50553-4")).click();

            //driver.manage().window().maximize();

        }
    }
于 2019-12-18T11:30:46.353 回答
0

在我们的案例中,问题并非特定于 Jenkins,而是Chrome 驱动程序在我们运行自动化测试的虚拟机下崩溃。

如果您登录到您的 VM 机器并且您的工作空间已被复制到其中,并在终端下运行与 Jenkins 上相同的 maven 命令,您应该能够观看测试运行,这可能是您识别和修复的一种方式问题。

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

于 2020-03-27T12:51:07.843 回答