无法在TestNG中启动Internet Explorer

时间:2013-10-22 10:48:24

标签: selenium-webdriver testng

我是TestNG的新手。这是我在eclipse中尝试过的代码,但启动Internet Explorer时出现问题。

它给出的错误是         org.openqa.selenium.remote.SessionNotFoundException:启动Internet Explorer时出现意外错误。保护模式设置对于所有区域都不相同。必须将启用保护模式设置为所有区域的相同值(启用或禁用)。 (警告:服务器未提供任何堆栈跟踪信息)

这是完整的代码......

package com.tcs.medmantra;
 import java.io.File;
import java.io.IOException;
import java.util.Set;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class Registration {
    WebDriver driver;
    WebElement element;
    WebElement element2;
    WebDriverWait waiter;
    @Test(priority = 1)
    public void register_With_Cash() throws RowsExceededException, BiffException, WriteException, IOException 
      {
        driver=new InternetExplorerDriver();
        driver.get("https://172.25.155.250/loginpage.aspx");
        //((JavascriptExecutor)driver).executeScript("window.resizeTo(1366, 768);");
        waiter = new WebDriverWait (driver, 40);
        driver.findElement(By.id("txtuname")).sendKeys("122337");
        driver.findElement(By.name("txtpwd")).sendKeys("Tcs!@345");
        driver.findElement(By.id("btnsubmit")).click();
        sleep(25000);



        //print URL
        String url = driver.getCurrentUrl();
        System.out.println(url);

    }



    @BeforeTest
    public void beforeTest() {      
        File file = new File("D:\\IEDriverServer.exe");
        System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

    }

    @AfterTest
    public void afterTest() {
        driver.quit();
    }



}

2 个答案:

答案 0 :(得分:1)

如错误所示,您需要为所有区域设置相同的保护模式,启用或禁用。首选将启用。见here

答案 1 :(得分:0)

更改您的代码以包含InternetExplorerDriver的路径。

File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();