对于参数类型int,String,运算符<未定义

0 java selenium

在编译时我收到错误说:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The operator < is undefined for the argument type(s) int, String
Run Code Online (Sandbox Code Playgroud)

错误在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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

chi*_*ity 5

在你的for循环中,你终止的条件是i < Res.get(i).getText().问题是这里的第二个参数是a String.你需要一个号码.(5大于或小于"香蕉"吗?这个问题没有任何意义.)

但我不确定是什么号码,因为我不清楚你的for循环试图实现什么...更好的格式化会有所帮助(也可能对你有所帮助)......