下面的方法布尔值总是带有假,请查看我的代码
public void customerUserCreationAdd(String state, String zip,
String isAdmin) throws InterruptedException {
pui = new Polled(driver);
new Actions(driver).moveToElement(pui.user_state).perform();
pui.user_state.clear();
pui.user_state.sendKeys(state);
new Actions(driver).moveToElement(pui.user_zip).perform();
pui.user_zip.clear();
pui.user_zip.sendKeys(zip);
new Actions(driver).moveToElement(pui.userReadonly).perform();
boolean ed = isAdmin.equals("IsReadOnlyNo");
if (ed == true) {
pui.userReadonly.click();
}
else {
pui.Btn_userSave.click();
}
}
从上面的方法中收集来自另一个类文件的所有参数值(即state,zip,isAdmin), 基于isAdmin String值将映射为两个条件(true / false) 因此,检查isAdmin值时始终使用false语句执行
同时直接传递isAdmin值(在方法内)条件正确检查 让我知道布尔条件无法使用参数值的原因或请指出我的错误
答案 0 :(得分:1)
在方法中声明另一个String变量,并在该String中分配参数值并继续其工作正常
代码
public void customerUserCreationAdd(String state, String zip,
String isAdmin) throws InterruptedException {
pui = new Polled(driver);
String isAdmin1 = isAdmin
new Actions(driver).moveToElement(pui.user_state).perform();
pui.user_state.clear();
pui.user_state.sendKeys(state);
new Actions(driver).moveToElement(pui.user_zip).perform();
pui.user_zip.clear();
pui.user_zip.sendKeys(zip);
new Actions(driver).moveToElement(pui.userReadonly).perform();
boolean ed = isAdmin1.equals(isAdmin);
if (ed == true) {
pui.userReadonly.click();
}
else {
pui.Btn_userSave.click();
}
}
答案 1 :(得分:-2)
if (ed) {
pui.userReadonly.click();
}
这就足够了..
我认为您使用的IsReadOnlyNo
应该是一个布尔变量。所以,你必须这样检查:
boolean ed = isAdmin.equals(IsReadOnlyNo);