当我运行上面的代码时它可以正常使用chrome和firefox但是当我使用IE运行时,它会在运行第7步时发生以下错误<* b>不明白它不起作用在IE中。
有人可以帮我解决这个问题。提前致谢
2017年11月20日下午2:58:39 org.openqa.selenium.remote.ErrorCodes toStatus 信息:HTTP状态:&#39; 404&#39; - &GT;不正确的JSON状态映射&#39;没有这样的窗口&#39; (400预期)
org.openqa.selenium.NoSuchWindowException:当前关注的窗口已关闭。 构建信息:版本:&#39; 3.6.0&#39;,版本:&#39; 6fbf3ec767&#39;,时间:&#39; 2017-09-27T15:28:36.4Z&#39; 系统信息:主机:&#39; ML-SIVAKUMARS-P&#39;,ip:&#39; 192.168.12.159&#39;,os.name:&#39; Windows 7&#39;,os.arch: &#39; amd64&#39;,os.version:&#39; 6.1&#39;,java.version:&#39; 1.8.0_121&#39; 驱动程序信息:org.openqa.selenium.ie.InternetExplorerDriver Capabilities [{proxy = Proxy(),acceptInsecureCerts = false,browserVersion = 11,se:ieOptions = {nativeEvents = true,browserAttachTimeout = 0,ie.ensureCleanSession = false,elementScrollBehavior = 0,enablePersistentHover = true,ie.browserCommandLineSwitches =,ie .forceCreateProcessApi = false,requireWindowFocus = false,initialBrowserUrl = http://localhost:2761/,ignoreZoomSetting = false,ie.fileUploadDialogTimeout = 3000,ignoreProtectedModeSettings = false},timeouts = {implicit = 0,pageLoad = 300000,script = 30000},browserName = internet explorer,pageLoadStrategy = normal,javascriptEnabled = true,platformName = WINDOWS,setWindowRect = true,platform = WINDOWS}] 会话ID:24a4d291-482e-4399-98fc-f2037c4da5bb ***元素信息:{Using = id,value = email}
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:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:356)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:402)
at org.openqa.selenium.By$ById.findElement(By.java:218)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
at com.org.learning.tests.TestDayTwo.firstTest(TestDayTwo.java:38)
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:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
答案 0 :(得分:5)
有两种方式:
方式1:设置INITIAL_BROWSER_URL:
File ieFile = new File("D:\\IEDriverServer_x64_2.53.0\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", ieFile.getAbsolutePath());
DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer();
ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.bing.com/");
driver = new InternetExplorerDriver(ieCaps);
//some operations on that site
driver.findElement(By.id("sb_form_q")).clear();
driver.findElement(By.id("sb_form_q")).sendKeys("Ripon Al Wasim");
driver.findElement(By.id("sb_form_go")).click();
方式2:要在目标计算机上设置注册表项: 仅对于IE 11,您需要在目标计算机上设置一个注册表项,以便驱动程序可以维护与其创建的Internet Explorer实例的连接。
对于32位Windows: 您必须在注册表编辑器中检查的密钥是HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BFCACHE。
对于64位Windows: 密钥为HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BFCACHE。
注意: 请注意,FEATURE_BFCACHE子项可能存在也可能不存在,如果不存在,则应创建该子项。要点:在此键内,创建名为iexplore.exe的值为0的DWORD值。
有关详细信息,请访问:https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
答案 1 :(得分:4)
自昨天以来,我一直在努力解决同样的问题,最终让我的考试工作
检查您是否拥有InternetExplorerDriver的所有required configurations。对我来说,这是我最终测试的保护模式设置,即使我在Win 10上。
希望它也能帮到你。
答案 2 :(得分:0)
对于我来说,由于网址“ /”末尾缺少斜杠而出现了错误
实际是http://example.com/ 但我正在通过http://example.com
答案 3 :(得分:0)
共有三个设置:
答案 4 :(得分:0)
在Internet Explorer中启用保护模式后,我的错误已解决。
设置->互联网选项->安全->选中所有区域的Enbale保护模式。