简体   繁体   English

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

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

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

org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information) org.openqa.selenium.NoSuchWindowException:无法在关闭的窗口中找到元素(警告:服务器未提供任何堆栈跟踪信息)

I have tried the driver.switchTo.window() method but it's not working. 我尝试过driver.switchTo.window()方法,但它无法正常工作。 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();
    }
}

Remove capability INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS and manually set your IE protected mode settings to be the same for all zones. 删除功能INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS并手动将IE保护模式设置设置为对所有区域都相同。

Source: 资源:

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

  2. NoSuchElementException is occurred during implementation of InternetExplorerDriver in Selenium WebDriver 在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);

The issue that helped me was to set init page (IE 11 both 32 and 64) 帮助我的问题是设置初始页面(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);
 }

The best bet here is to make some tweaks to the registry: 这里最好的选择是对注册表进行一些调整:

  1. Go to registry edit ( regedit from windows run) 转到注册表编辑(从Windows运行regedit

  2. Look in your registry under the HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings\\Zones . HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings\\Zones下的注册表中查找。 Over there, you should see keys number 0-4 . 在那里,你应该看到键号0-4。 Under these keys 0-4, look for a value named 2500 在这些键0-4下,查找名为2500的值

  3. For all the keys from 0-4, have the same data for value 2500. For example, for key 0 if the value 2500 has data as 3 (hex data), then make the data for value 2500 as 3 for all the other keys (1,2,3,4). 对于0-4中的所有键,对于值2500具有相同的数据。例如,对于键0,如果值2500具有数据3(十六进制数据),则对于所有其他键,将值2500的数据设为3 (1,2,3,4)。

  4. Now try to run the script. 现在尝试运行脚本。

暂无
暂无

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

相关问题 带有Selenium WebDriver的IE 11:org.openqa.selenium.NoSuchWindowException - IE 11 with Selenium WebDriver: org.openqa.selenium.NoSuchWindowException org.openqa.selenium.NoSuchWindowException:无法获取浏览器 - org.openqa.selenium.NoSuchWindowException: Unable to get browser Selenium chromedriver丢失窗口句柄。 org.openqa.selenium.NoSuchWindowException:没有此类窗口错误 - Selenium chromedriver losing window handles. org.openqa.selenium.NoSuchWindowException: no such window error 使用Java的Silenium Webdriver:线程“ main” org.openqa.selenium.ElementNotVisibleException中的异常: - Silenium webdriver using Java: Exception in thread “main” org.openqa.selenium.ElementNotVisibleException: org.openqa.selenium.NoSuchElementException WebDriver是否在Java中? - org.openqa.selenium.NoSuchElementException WebDriver in Java? Internet Explorer中的Selenium Webdriver - Selenium Webdriver in Internet explorer org.openqa.selenium.WebDriverException:使用Selenium Java和Webdriver时连接被拒绝(Linux头没有Xvfb) - org.openqa.selenium.WebDriverException: connection refused while using Selenium Java and webdriver (linux headless with Xvfb) 无法使用 Selenium 和 Java 11 导入 o​​rg.openqa.selenium.WebDriver - Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11 我收到“线程“main”java.lang.NoClassDefFoundError 中的异常:org/openqa/selenium/WebDriver” - I am getting an "exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver" 线程“主”中的异常 java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver - Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM