5

While using IE for automation using Selenium Webdriver, I am able to open the URL but finding the element on that page is throwing the following exception:

org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)

I have tried the driver.switchTo.window() method but it's not working. I have searched it for hours and I am not getting anywhere.

Here's the code:

public static Selenium selenium;

public static void main(String args[]) {

    try {

        System.setProperty(
            "webdriver.ie.driver",
            "D:\\Driver\\IEDriverServer_Win32_2.32.3_latest\\IEDriverServer.exe");

        DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
        capab.setCapability(
            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
            true);

        WebDriver driver = new InternetExplorerDriver(capab);
        driver.get("http://www.google.com");
        driver.findElement(By.xpath(".//*[@id='addlang']/a[1]")).click();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
4

4 回答 4

7

删除功能INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS并手动将您的 IE 保护模式设置设置为对所有区域都相同。

资源:

  1. http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html

  2. 在 Selenium WebDriver 中实现 InternetExplorerDriver 期间发生 NoSuchElementException

于 2013-05-15T08:03:31.743 回答
3
case "ie_driver":           

    //IE CODE
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "https://testvmm6.partnersonline.com/vmm");
    cap.internetExplorer().setCapability("ignoreProtectedModeSettings", true);

    System.setProperty("webdriver.ie.driver", System.getProperty("user.dir")+"//exe//IEDriverServer1.exe");
    cap.setCapability("IE.binary", "C:/Program Files (x86)/Internet Explorer/iexplore.exe");
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setJavascriptEnabled(true);
    cap.setCapability("requireWindowFocus", true);
    cap.setCapability("enablePersistentHover", false);
于 2014-12-31T07:07:13.970 回答
1

帮助我的问题是设置初始化页面(IE 11 32 和 64)

 private WebDriver getIEDriver() {
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, INIT_PAGE);

    File file = new File("E:/drivers/IEDriverServer.exe");
    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
    return new InternetExplorerDriver(cap);
 }
于 2015-07-22T09:09:36.170 回答
1

最好的办法是对注册表进行一些调整:

  1. 转到注册表编辑(regedit从 Windows 运行)

  2. 在您的注册表中查找HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Zones. 在那里,您应该看到 0-4 号键。在这些键 0-4 下,查找名为 2500 的值

  3. 对于 0-4 的所有键,值 2500 具有相同的数据。例如,对于键 0,如果值 2500 的数据为 3(十六进制数据),则将值 2500 的数据为所有其他键的 3 (1,2,3,4)。

  4. 现在尝试运行脚本。

于 2016-08-11T15:22:35.750 回答