Selenium未正确解释属性值
如果条件在Selenium中无法正常工作,则返回My属性值。它正在向控制台打印字符串值true,但以下假设打印SMS号码的条件复选框被禁用。打印其他输出Selenium未正确解释属性值,selenium,Selenium,如果条件在Selenium中无法正常工作,则返回My属性值。它正在向控制台打印字符串值true,但以下假设打印SMS号码的条件复选框被禁用。打印其他输出 String value=customerSectionSMSNumber.getAttribute("readonly"); System.out.println("Value = "+ value); if ( value == "true") { System.out.printl
String value=customerSectionSMSNumber.getAttribute("readonly");
System.out.println("Value = "+ value);
if ( value == "true") {
System.out.println("SMS number checkbox is disabled");
}` else {
System.out.println(customerSectionSMSNumber.getAttribute("readonly"));
}
试试这个代码
String value=customerSectionSMSNumber.getAttribute("readonly");
System.out.println("Value = "+ value);
if(value!=null){
if ( value.contains("true")) {
System.out.println("SMS number checkbox is disabled");
}` else {
System.out.println(customerSectionSMSNumber.getAttribute("readonly"));
}
}
不能将字符串值与等于运算符进行比较。您必须使用下面给出的字符串类的
equals
或contains
方法
String value=customerSectionSMSNumber.getAttribute("readonly");
System.out.println("Value = "+ value);
if ( value.equals("true")) {
System.out.println("SMS number checkbox is disabled");
}` else {
System.out.println(customerSectionSMSNumber.getAttribute("readonly"));
}
String value=customerSectionSMSNumber.getAttribute("readonly");
System.out.println("Value = "+ value);
if ( Boolean.parseBoolean(value)) {
System.out.println("SMS number checkbox is disabled");
}` else {
System.out.println(customerSectionSMSNumber.getAttribute("readonly"));
}
否则,将字符串值转换为布尔值,并使用下面给出的if子句
String value=customerSectionSMSNumber.getAttribute("readonly");
System.out.println("Value = "+ value);
if ( value.equals("true")) {
System.out.println("SMS number checkbox is disabled");
}` else {
System.out.println(customerSectionSMSNumber.getAttribute("readonly"));
}
String value=customerSectionSMSNumber.getAttribute("readonly");
System.out.println("Value = "+ value);
if ( Boolean.parseBoolean(value)) {
System.out.println("SMS number checkbox is disabled");
}` else {
System.out.println(customerSectionSMSNumber.getAttribute("readonly"));
}