如何在web驱动程序java的if条件下使用断言
我已经通过了登录用户名和密码的过程,以便从excel数据表中进行测试。但是,现在我陷入了断言命令在if条件下实际插入然后停止并中断该循环的情况。请帮助我如何在web驱动程序java的if条件下使用断言,java,selenium,selenium-webdriver,automation,Java,Selenium,Selenium Webdriver,Automation,我已经通过了登录用户名和密码的过程,以便从excel数据表中进行测试。但是,现在我陷入了断言命令在if条件下实际插入然后停止并中断该循环的情况。请帮助我 for (int i = 1; i <= sheet.getLastRowNum(); i++) { // Import data for Email. /* cell = sheet.getRow(i).getCell(1);
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
// Import data for Email.
/* cell = sheet.getRow(i).getCell(1);
cell.setCellType(Cell.CELL_TYPE_STRING);*/
DataFormatter formatter = new DataFormatter();
Cell cell = sheet.getRow(i).getCell(1);
String j_username = formatter.formatCellValue(cell);
driver.findElement(By.id("loginUser_UserName")).sendKeys(cell.toString());
/* // Import data for password.
cell = sheet.getRow(i).getCell(2);
cell.setCellType(Cell.CELL_TYPE_STRING);*/
Cell cell1 = sheet.getRow(i).getCell(2);
String j_username1 = formatter.formatCellValue(cell1);
System.out.println(cell1.toString());
driver.findElement(By.id("loginUser_Password")).sendKeys(cell1.toString());
driver.findElement(By.id("loginUser_LoginButton")).click();
}
for(int i=1;i您可以检查元素是否存在
IWebElement e = driver.FindElement(By.Id("Your_SignOut_Button_Id"));
在你的情况下,你想要断言
Debug.Assert(driver.FindElement(By.Id("Your_SignOut_Button_Id")), "YOUR MESSGAE TO BE DISPLAYED!");
您获得了必需的元素(即不为NULL)或未获得(即为NULL)
请展示您迄今为止所做的尝试步骤1.我已获取了包含姓名和密码列的工作表。步骤2.从Excel中读取数据。步骤3.登录按钮单击请发布您一直使用的代码的简明版本
if (e == NULL) {
break;
}
else {
continue;
}