开发者

Selenium Script For IE

I got this error , while running selenium script for Internet Explorer 9.

 Exception in thread "main" org.openqa.selenium.WebDriverException: Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information); du开发者_如何学运维ration or timeout: 193 milliseconds


There is a bug report discussing this issue: http://code.google.com/p/selenium/issues/detail?id=1795

If you turn ON protected mode in ALL Internet Explorer Zones (Security Tab in IE settings) I believe the issue is resolved.


DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(
    InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
    true
); 
WebDriver dr = new InternetExplorerDriver(ieCapabilities);


Don't do it through code here is why http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html


WebDriver driver = null;
@BeforeSuite
public void suiteSetup() {
    System.setProperty("webdriver.chrome.driver", "D:\\drivers\\chromedriver.exe");
    driver = new ChromeDriver();
}

//Simply create some blank annotations over here for validation purpose
@BeforeTest
public void testSetup() {
    
}

@BeforeMethod
public void methodSetup() {
    
}

@Test

public void testMethod1() throws IOException {
  FileInputStream  file = new FileInputStream("C:\\Users\\Desktop\\Leave_Details.xlsx");
    XSSFWorkbook wb = new XSSFWorkbook(file);// .xslx file

HSSFWorkbook wb = new HSSFWorkbook(file);- .xsl file

    XSSFSheet sh = wb.getSheet("Sheet1");

HSSFSheet sh = wb.getSheet("Sheet1");// Sheet1 need to be replaced with actual tab name System.out.println(sh.getRow(0).getCell(0).getStringCellValue()); // Gives the data. need to update the row and column numbers accordingly

    driver.get("url");
    //Get the title of the application
    String strTitle = driver.getTitle();
    System.out.println("Title of the page:"+strTitle);
    
    //No of elements 
    List<WebElement> listElements = driver.findElements(By.xpath("")); // Use findelemet'S' not findelement
    System.out.println(listElements.size());
    
}
@Parameters ({"Type","Name"}) // Add name of parameters added in testng.xml and give name over here and do the same naming in method
@Test
public void testMethod2(String strType, String strName) {
    System.out.println(strType); //Gives the parameter value specified in testng.xml
}

@AfterTest
public void testTearDown() {
    
}

@AfterMethod
public void methodTearDown() {
    
}

@AfterSuite
public void suiteTearDown() {
    driver.close();
}


File src=new File("filepath/excelsheetname.xlsx");

// load file
FileInputStream fis=new FileInputStream(src);

// Load workbook
XSSFWorkbook wb=new XSSFWorkbook(fis);

// Load sheet- Here we are loading first sheetonly
XSSFSheet sh1= wb.getSheetAt(0);

// getRow() specify which row we want to read.
// and getCell() specify which column to read.
// getStringCellValue() specify that we are reading String data.

System.out.println(sh1.getRow(0).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(0).getCell(1).getStringCellValue());
System.out.println(sh1.getRow(1).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(1).getCell(1).getStringCellValue());
System.out.println(sh1.getRow(2).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(2).getCell(1).getStringCellValue());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜