我在运行Internet Explorer 9的selenium脚本时遇到此错误。
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
答案 0 :(得分:8)
有一个错误报告讨论了这个问题:http://code.google.com/p/selenium/issues/detail?id=1795
如果在所有Internet Explorer区域(IE设置中的“安全”选项卡)中打开保护模式,我认为问题已解决。
答案 1 :(得分:0)
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true
);
WebDriver dr = new InternetExplorerDriver(ieCapabilities);
答案 2 :(得分:0)
不要通过代码来做这就是原因 http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html
答案 3 :(得分: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 =新的HSSFWorkbook(文件);-.xsl文件
XSSFSheet sh = wb.getSheet("Sheet1");
HSSFSheet sh = wb.getSheet(“ Sheet1”); //需要用实际的选项卡名称替换Sheet1 System.out.println(sh.getRow(0).getCell(0).getStringCellValue()); //提供数据。需要相应地更新行号和列号
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();
}
答案 4 :(得分: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());