无法使用Selenium Web Driver在IE中打开任何网页

时间:2017-07-21 08:53:21

标签: java selenium internet-explorer selenium-webdriver automated-tests

我想在IE中打开一个google网页(google.com),但在运行我的脚本时显示“org.openqa.selenium.NoSuchWindowException:无法获取浏览器(警告:服务器未提供任何堆栈跟踪信息)显示正在运行“错误。 我正在使用IE: - 11 窗户: - 8.1; 64位。

我的代码是: -

System.setProperty("Webdriver.ie.driver", "C:\\IEDriverServer.exe");
    WebDriver driver = new InternetExplorerDriver();
    driver.get("https://google.co.in");
//  driver.get("javascript:document.getElementById('overridelink').click();");
System.out.println(driver.getCurrentUrl()); 
     Thread.sleep(3000);
     System.out.println(driver.getCurrentUrl());    
    String PageTitle = driver.getTitle();
Thread.sleep(3000);

    if (PageTitle.equals("Google")){
        System.out.println("test case passed");
    }
    else {
        System.out.println("failed");
    }

2 个答案:

答案 0 :(得分:0)

尝试以下代码:这在我的最后工作正常

System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
    DesiredCapabilities cappabilities = DesiredCapabilities.internetExplorer();        
    cappabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
    cappabilities.setCapability("platform", "WIN8"); 
    cappabilities.setCapability("version", "11"); 
    cappabilities.setCapability("browserName", "internet explorer");
    cappabilities.setCapability("ignoreProtectedModeSettings",1);
    cappabilities.setCapability("nativeEvents","false");
    cappabilities.setCapability("requireWindowFocus","true");
    WebDriver driver = new InternetExplorerDriver(cappabilities);
    driver.manage().window().maximize();
    driver.get("https://google.co.in");
       System.out.println(driver.getCurrentUrl()); 
         Thread.sleep(3000);
         System.out.println(driver.getCurrentUrl());    
        String PageTitle = driver.getTitle();
    Thread.sleep(3000);

        if (PageTitle.equals("Google")){
            System.out.println("test case passed");
        }
        else {
            System.out.println("failed");
        }

如果这是在你的最后工作,请告诉我

屏幕截图: - enter image description here

enter image description here

答案 1 :(得分:0)

首先在IE浏览器中设置保护模式设置。请按照以下步骤操作:

  1. 打开IE浏览器
  2. 点击设置
  3. 单击Internet选项
  4. 转到“安全性”标签
  5. 单击Internet区域以选择一个区域并查看其保护模式属性。
  6. 现在选中“启用保护模式”复选框。
  7. 需要为所有其他区域设置。 (Internet,本地Intranet,受信任的站点,受限制的站点)
  8. 点击确定
  9. 再次单击设置
  10. 确保将Internet Explorer的“缩放”属性设置为100%

在Selenium脚本中使用以下功能:

System.setProperty("webdriver.ie.driver","C:\\IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURIY_DOMAINS, true);
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capabilities.setCapability("allow-blocked-content", true);
WebDriver driver = new InternetExplorerDriver(capabilities);

再次运行Selenium脚本。这次它将起作用。