繁体   English   中英

异常(org.openqa.selenium.NoSuchWindowException):在Internet Explorer中使用Selenium WebDriver和Java

[英]Exception (org.openqa.selenium.NoSuchWindowException): using Selenium WebDriver with Java in Internet Explorer

使用IE进行自动化使用Selenium Webdriver时,我可以打开URL,但在该页面上找到该元素会引发以下异常:

org.openqa.selenium.NoSuchWindowException:无法在关闭的窗口中找到元素(警告:服务器未提供任何堆栈跟踪信息)

我尝试过driver.switchTo.window()方法,但它无法正常工作。 我已经搜索了几个小时,我没有到达任何地方。

这是代码:

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();
    }
}

删除功能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

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);

帮助我的问题是设置初始页面(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);
 }

这里最好的选择是对注册表进行一些调整:

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

  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. 现在尝试运行脚本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM