Internet Explorer中的selenium webdriver即使在完成所有必需的设置后也会抛出错误

时间:2015-12-08 06:51:19

标签: selenium

public class FirstTest {    WebDriver driver;   @Test   public void test()  {   System.setProperty("webdriver.ie.driver","C:\\Users\\Priyanka\\Documents\\datadriver\\IEDriverServer.exe");     driver=new InternetExplorerDriver(); //driver=new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://gmail.com"); driver.findElement(By.id("userid")).sendKeys("Abc@gmail.coms"); driver.findElement(By.id("pwd")).sendKeys("abc@167"); driver.findElement(By.name("Submit")).click(); } }  

这是我的代码。它会打开给定的网址,但在尝试查找webelement错误消息时会出错:

  

失败:测试org.openqa.selenium.NoSuchWindowException:无法找到   关闭窗口上的元素(警告:服务器未提供任何内容   stacktrace information)命令持续时间或超时:28毫秒   构建信息:版本:'2.48.2',修订版:'41bccdd',时间:'2015-10-09   19:55:52'系统信息:主持人:'Priyanka-PC',ip:'100.74.201.94',   os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',   java.version:'1.7.0_79' ***元素信息:{Using = id,value = userid}   会议ID:fc075a9b-5a50-42fa-ba96-ce2258254d4a驱动信息:   org.openqa.selenium.ie.InternetExplorerDriver功能   [{platform = WINDOWS,javascriptEnabled = true,elementScrollBehavior = 0,   ignoreZoomSetting = false,enablePersistentHover = true,   ie.ensureCleanSession = false,browserName = internet explorer,   enableElementCacheCleanup = true,unexpectedAlertBehaviour = dismiss,   version = -1,pageLoadStrategy = normal,ie.usePerProcessProxy = false,   cssSelectorsEnabled = true,ignoreProtectedModeSettings = false,   requireWindowFocus = false,initialBrowserUrl = http://localhost:22334/,   handlesAlerts = true,ie.forceCreateProcessApi = false,nativeEvents = true,   browserAttachTimeout = 0,ie.browserCommandLineSwitches =,   takeScreenshot = true}] at   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)     在   org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)     在   org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)     在   org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)     在   org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)     在   org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:403)     在org.openqa.selenium.By $ ById.findElement(By.java:218)at at   org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345)     在demo.FirstTest.test(FirstTest.java:20)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:606)at   org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)     在org.testng.internal.Invoker.invokeMethod(Invoker.java:643)at   org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)at at   org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)at at   org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)     在   org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)     在org.testng.TestRunner.privateRun(TestRunner.java:782)at   org.testng.TestRunner.run(TestRunner.java:632)at   org.testng.SuiteRunner.runTest(SuiteRunner.java:366)at   org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)at at   org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)at at   org.testng.SuiteRunner.run(SuiteRunner.java:268)at   org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)at   org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)at   org.testng.TestNG.runSuitesSequentially(TestNG.java:1246)at at   org.testng.TestNG.runSuitesLocally(TestNG.java:1171)at at   org.testng.TestNG.run(TestNG.java:1066)at   org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)at at   org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)at at   org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)

我做了以下设置:

  1. 设置安全区域
  2. 在注册表文件中输入
  3. 设置环境变量
  4. 将默认缩放尺寸设置为100请指导我该怎么做。
  5. 此代码在firefox中运行良好

1 个答案:

答案 0 :(得分:0)

试试这个。 在IE浏览器中为所有区域启用保护模式。应检查所有区域。 它对我有用。