6

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); duration or timeout: 193 milliseconds
Mohyt
  • 990
  • 2
  • 10
  • 26

5 Answers5

8

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.

user247702
  • 23,641
  • 15
  • 110
  • 157
  • Thanks its works , but another exception occurs: org.apache.http.impl.client.DefaultRequestDirector tryExecute INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed Sep 30, 2011 1:49:35 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute INFO: Retrying request – Mohyt Sep 30 '11 at 08:24
  • If you get another exception, you should open a bug report at the selenium website. – user247702 Sep 30 '11 at 12:55
0
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(
    InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
    true
); 
WebDriver dr = new InternetExplorerDriver(ieCapabilities);
Matthias
  • 7,432
  • 6
  • 55
  • 88
nikil
  • 9
  • 1
  • +1. This works perfectly for me, and better to do it programmatically than changing browser settings if you want to port your test cases. – pMan May 28 '12 at 06:38
0

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

Manipal
  • 195
  • 3
  • 7
0
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 scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy somewhere FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png")); – Seleniumuser Aug 15 '20 at 13:47
  • driver.switchTo().alert().dismiss(); driver.switchTo().alert().accept(); driver.switchTo().alert().getText(); driver.switchTo().alert().sendKeys("Text"); – Seleniumuser Aug 15 '20 at 13:59
  • TakesScreenshot scrShot =((TakesScreenshot)webdriver); //Call getScreenshotAs method to create image file File SrcFile=scrShot.getScreenshotAs(OutputType.FILE); //Move image file to new destination File DestFile=new File(fileWithPath); //Copy file at destination FileUtils.copyFile(SrcFile, DestFile); – Seleniumuser Aug 15 '20 at 14:14
  • @Test @Parameters({ "username", "password" }) public void testCaseTwo(String username, String password) { driver.findElement(By.xpath("")).sendKeys(username); driver.findElement(By.xpath("")).sendKeys"password"); – Seleniumuser Aug 15 '20 at 15:06
  • static Logger logger = Logger.getLogger("Demo16_Basic_Configurator.class"); public static void main(String[] args)throws Exception { WebDriver driver; BasicConfigurator.configure(); driver.get("url"); logger.info("Opening Pack and Go application"); – Seleniumuser Aug 15 '20 at 17:31
  • Parameter in Testng xml: @Parameters({ "username", "password" }) @Test public void testCaseTwo(String username, String password) { System.out.println("Parameter for User Name passed as :- " + username); System.out.println("Parameter for Password passed as :- " + password); } – Seleniumuser Sep 03 '20 at 14:45
  • WebDriver driver = new FirefoxDriver(); //Creating an object of FirefoxDriver driver.manage().window().maximize(); driver.manage().deleteAllCookies(); driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("https://www.google.com/"); – Seleniumuser Sep 03 '20 at 14:46
  • Try below code, this will print all cells data, // Grab the table WebElement table = driver.findElement(By.id("divListView")); // Now get all the TR elements from the table List allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List cells = row.findElements(By.tagName("td")); // Print the contents of each cell for (WebElement cell : cells) { System.out.println(cell.getText()); } } – Seleniumuser Sep 03 '20 at 14:47
  • Logger: Trace < Debug < Info < Warn < Error < Fatal. Static Logger logger = Logger.getLogger(“classname.class”); Public static void main(String[] args)throws Exception{ webDriver driver; BasicConfigurator.configure(); Logger.info(“opening application”); No of hyperlinks List links = driver.findElements(By.tagName("a")); System.out.println(links.size()); – Seleniumuser Sep 03 '20 at 14:49
  • Specific text exists: String bodyText = driver.findElement(By.tagName("body")).getText(); Assert.assertTrue("Text not found!", bodyText.contains(text)); If( boxyText.contains(text) == “specifictext”) { Syso.print(“”); } Else System.out.println(“”); WebElement textDemo = driver.findElement(By.xpath("//*[text()='Write and Earn']")); if(textDemo.isDisplayed()) { System.out.println("Element found using text"); } else System.out.println("Element not found"); } – Seleniumuser Sep 03 '20 at 14:50
  • Table data: //No.of Columns List col = wd.findElements(By.xpath(".//*[@id=\"leftcontainer\"]/table/thead/tr/th")); System.out.println("No of cols are : " +col.size()); //No.of rows List rows = wd.findElements(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td[1]")); System.out.println("No of rows are : " + rows.size()); – Seleniumuser Sep 03 '20 at 14:50
  • Specific row and column data: 3rd row and 2nd column //To find third row of table WebElement tableRow = baseTable.findElement(By.xpath("//*[@id=\"leftcontainer\"]/table/tbody/tr[3]")); String rowtext = tableRow.getText(); System.out.println("Third row of table : "+rowtext); //to get 3rd row's 2nd column data WebElement cellIneed = tableRow.findElement(By.xpath("//*[@id=\"leftcontainer\"]/table/tbody/tr[3]/td[2]")); String valueIneed = cellIneed.getText(); System.out.println("Cell value is : " + valueIneed); – Seleniumuser Sep 03 '20 at 14:51
  • //To verify if name risetop exists or not Public static String cellTex; List tableRows=driver.findElements(By.xpath("//table/tbody/tr")); int rowsize=tableRows.size(); System.out.println(rowsize); List tableCol=driver.findElements(By.xpath("//table/thead/tr/th")); for(int i=1;i – Seleniumuser Sep 03 '20 at 14:52
  • if(cellTex.contains("Risetop")){ System.out.println("Name EXISTS"); } else{ System.out.println("Doesnt Exist"); } – Seleniumuser Sep 03 '20 at 14:53
  • //get complete table data for(int i=1;i – Seleniumuser Sep 03 '20 at 14:53
  • excel utility - right click src->new package com.test.utility. then new class with ExcelUtils.https://www.toolsqa.com/selenium-webdriver/testng-data-provider-excel/ – Seleniumuser Sep 03 '20 at 15:31
  • Import java.util.ArrayList; Import com.excel.utility.Xls_Reader; public class TestUtil { static Xls_Reader reader; public static ArrayList getDataFromExcel(){ ArrayList myData = new ArrayList(); try{ reader= new Xls_Reader(“/Users/documents/testdata.xlsx”); } catch (Exception e){ e.printStackTrace(); } – Seleniumuser Sep 03 '20 at 16:04
  • for ( int rowNum=2;rowNum<=reader.gerRowCount(“sheetnameinexcel”);rowNum++){ String firstName = reader.getCellData(“sheetname”, “firstname”, rowNum); String lastName = reader.getCellData(“sheetname”, “lastname”, rowNum); Object ob[] = { firstName, lastName}; myData.add(ob); } return myData; } } – Seleniumuser Sep 03 '20 at 16:05
  • @DataProver public Iterator getTestData(){ ArrayList testData = Testutil.getDataFromExcel(); Return testData.iterator(); } – Seleniumuser Sep 03 '20 at 16:14
  • @Test(dataProvider=”getTestData”) Public void sampleTest(String firstName, String lastName){ – Seleniumuser Sep 03 '20 at 16:16
  • String assertionString = “testing”; SoftAssert softAssert=new SoftAssert(); softAssert.assertEquals(“testing”, assertionString); – Seleniumuser Sep 03 '20 at 16:22
  • sh1.getRow(0).createCell(2).setCellValue("2.41.0"); sh1.getRow(1).createCell(2).setCellValue("2.5"); sh1.getRow(2).createCell(2).setCellValue("2.39");https://learn-automation.com/read-and-write-excel-files-in-selenium/ – Seleniumuser Sep 03 '20 at 16:25
  • /@BeforeSuite /@AfterSuite /@BeforeTest /@AfterTest /@BeforeGroups /@AfterGroups /@BeforeClass /@AfterClass /@BeforeMethod /@AfterMethod – Seleniumuser Sep 03 '20 at 16:55
0
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());
David Buck
  • 3,752
  • 35
  • 31
  • 35