webdriver调用ie浏览器报错:
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed
解决方法:
System.setProperty("webdriver.ie.driver", "C:\Users\ssatyanarayana\Downloads\IEDriverServer.exe");// opening the IE with recomended settingsInternetExplorerDriverService service = InternetExplorerDriverService.createDefaultService();DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "about:blank");capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);capabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);WebDriver driver = new InternetExplorerDriver(service, capabilities);
摘自:http://www.linkedin.com/groups/Unable-do-any-actions-using-4067187.S.5826123920205426689
先说明这个是一个类里面的一个方法,public是表示这个方法是可以最大范围的被调用到,属于公共的。 WebDriver 是一个返回类型这个返回类型是其他类定义的,你只需要知道调用这个方法最后返回的东西 是一种已经被定义好的一种格式。 openBrowser是方法名,如果想要调用这个方法就需要这个方法名称,传入对应的参数 WebDriver driver ,driver就是一个参数。System.setProperty("webdriver.ie.driver", "res/IEDriverServer.exe")这句话的意思是在系统配置文件中加入配置,配置文件中的webdriver.ie.driver字段设置参数为res/IEDriverServer.exe就相当于如果加载配置文件,就会加载IEDriverServer.exe工具调用它。DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); 这句话是创建了 DesiredCapabilities.internetExplorer(); 被capabilities 对象引用。capabilities 这个就具有了DesiredCapabilities.internetExplorer()的方法和属性。capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);这句话就是加载了浏览器的配置设定,也是在capabilities对象中的Capability属性中加入了InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS参数,应该是规定的设定必要条件。 driver = new InternetExplorerDriver(capabilities); return driver;这句话就相当于创建一个浏览器驱动,把之前创建的对象加入到这个驱动中,把返回的驱动对象返回给调用这个方法的类中。这个只是一个返回驱动设定参数的方法,但是真正执行打开ie的操作不是这个方法,是调用这个方法的地方,这个方法只是一个配置而已。
webdriver调用ie浏览器报错:
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed
解决方法:
System.setProperty("webdriver.ie.driver", "C:\Users\ssatyanarayana\Downloads\IEDriverServer.exe");
// opening the IE with recomended settings
InternetExplorerDriverService service = InternetExplorerDriverService.createDefaultService();
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "about:blank");
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
capabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
WebDriver driver = new InternetExplorerDriver(service, capabilities);
摘自:http://www.linkedin.com/groups/Unable-do-any-actions-using-4067187.S.5826123920205426689