Selenium Script For IE
Asked Answered
M

5

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
Malleus answered 30/9, 2011 at 8:14 Comment(0)
C
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.

Cobham answered 30/9, 2011 at 8:18 Comment(2)
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 requestMalleus
If you get another exception, you should open a bug report at the selenium website.Cobham
F
0
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(
    InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
    true
); 
WebDriver dr = new InternetExplorerDriver(ieCapabilities);
Faretheewell answered 3/5, 2012 at 7:17 Comment(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.Orianna
E
0

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

Effectuate answered 13/6, 2014 at 15:3 Comment(0)
P
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();
}
Penitentiary answered 15/8, 2020 at 13:44 Comment(24)
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"));Penitentiary
driver.switchTo().alert().dismiss(); driver.switchTo().alert().accept(); driver.switchTo().alert().getText(); driver.switchTo().alert().sendKeys("Text");Penitentiary
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);Penitentiary
<parameter name="browser" value="Firefox"/> <parameter name="username" value="testuser"/> <parameter name="password" value="testpassword"/>Penitentiary
@Test @Parameters({ "username", "password" }) public void testCaseTwo(String username, String password) { driver.findElement(By.xpath("")).sendKeys(username); driver.findElement(By.xpath("")).sendKeys"password");Penitentiary
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");Penitentiary
Parameter in Testng xml: <parameter name = "myName" value="manisha"/> @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); }Penitentiary
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("google.com/");Penitentiary
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<WebElement> allRows = table.findElements(By.tagName("tr")); // And iterate over them, getting the cells for (WebElement row : allRows) { List<WebElement> cells = row.findElements(By.tagName("td")); // Print the contents of each cell for (WebElement cell : cells) { System.out.println(cell.getText()); } }Penitentiary
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<WebElement> links = driver.findElements(By.tagName("a")); System.out.println(links.size());Penitentiary
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"); }Penitentiary
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());Penitentiary
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);Penitentiary
//To verify if name risetop exists or not Public static String cellTex; List<WebElement> tableRows=driver.findElements(By.xpath("//table/tbody/tr")); int rowsize=tableRows.size(); System.out.println(rowsize); List<WebElement> tableCol=driver.findElements(By.xpath("//table/thead/tr/th")); for(int i=1;i<rowsize;i++){ for(int j=1;j<colSize;j++){ WebElement firstIndex=driver.findElement(By.xpath("//table/tbody/tr["+i+"]/td["+j+"]")); if(j==1){ cellTex=cellTex+firstIndex.getText(); System.out.println(cellTex); } } }Penitentiary
if(cellTex.contains("Risetop")){ System.out.println("Name EXISTS"); } else{ System.out.println("Doesnt Exist"); }Penitentiary
//get complete table data for(int i=1;i<rowsize;i++){ for(int j=1;j<colSize;j++){ WebElement firstIndex=driver.findElement(By.xpath("//table/tbody/tr["+i+"]/td["+j+"]")); cellTex=cellTex+firstIndex.getText(); System.out.println(cellTex); } }Penitentiary
excel utility - right click src->new package com.test.utility. then new class with ExcelUtils.toolsqa.com/selenium-webdriver/testng-data-provider-excelPenitentiary
Import java.util.ArrayList; Import com.excel.utility.Xls_Reader; public class TestUtil { static Xls_Reader reader; public static ArrayList<Object[]> getDataFromExcel(){ ArrayList<Object[]> myData = new ArrayList<Object[]>(); try{ reader= new Xls_Reader(“/Users/documents/testdata.xlsx”); } catch (Exception e){ e.printStackTrace(); }Penitentiary
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; } }Penitentiary
@DataProver public Iterator<Object[]> getTestData(){ ArrayList<Object[]> testData = Testutil.getDataFromExcel(); Return testData.iterator(); }Penitentiary
@Test(dataProvider=”getTestData”) Public void sampleTest(String firstName, String lastName){Penitentiary
String assertionString = “testing”; SoftAssert softAssert=new SoftAssert(); softAssert.assertEquals(“testing”, assertionString);Penitentiary
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");learn-automation.com/read-and-write-excel-files-in-seleniumPenitentiary
/@BeforeSuite /@AfterSuite /@BeforeTest /@AfterTest /@BeforeGroups /@AfterGroups /@BeforeClass /@AfterClass /@BeforeMethod /@AfterMethodPenitentiary
P
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());
Penitentiary answered 15/8, 2020 at 21:29 Comment(1)
/@BeforeSuite /@BeforeTest /@BeforeClass /@BeforeMethod /@Test /@AfterMethod /@AfterClass /@AfterTest /@AfterSuitePenitentiary

© 2022 - 2024 — McMap. All rights reserved.