编译时我收到错误说:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The operator < is undefined for the argument type(s) int, String
错误位于 for循环。
package automationFramework;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class DropDownMd {
private static WebDriver driver = null;
public static void main(String[] args) {
driver = new FirefoxDriver();
driver.get("http://www.irctc.com/menu.html ");
driver.findElement(By.linkText("Feedback")).click();
WebElement Servcsdrop = driver.findElement(By.id("NU_SERVICE_ID"));
Select Val = new Select(Servcsdrop);
List<WebElement> Res = Val.getOptions();
boolean f = false;
for (int i = 0; i < Res.get(i).getText(); i++)
// error is here
if (Val.equals("TOURISM")) {
f = true;
}
if (f) {
System.out.println("tourism is present");
} else {
System.out.println("Tourism is not present");
}
}
}
答案 0 :(得分:5)
在for
循环中,您的终止条件是i < Res.get(i).getText()
。问题是这里的第二个参数是String
。你需要一个号码。 (5大于或小于&#34;香蕉&#34;?这个问题没有任何意义。)
但是我不确定是什么号码,因为我不清楚你的for
循环试图实现什么......更好的格式化会有所帮助(也可能对你有帮助)。 ..
答案 1 :(得分:1)
这个错误是不言自明的。在for(int i=0; i < Res.get(i).getText(); i++)
,您要检查int
是否小于 a String
。我想你想要文本长度所以你应该这样做:
for(int i=0; i < Res.get(i).getText().length(); i++)
如果没有,请说明您要对循环进行的操作。