我下载的验证码不是验证角色

时间:2016-11-15 21:23:29

标签: java selenium selenium-webdriver webdriver

Screenshot

int count = 0;         String [] CRI = {                 "选择角色。",                 " 0 - ABCD",                 " 1 - EFMK",                 " 2 - XYZV"};

blogs_path

附件CRI [\] \ [1 \] />

1 个答案:

答案 0 :(得分:0)

我会使用Select类来处理任何SELECT标记。请尝试下面的代码。

String[] expectedIssues = { "Select Client Reporting Issue...", "0 - ABCD", "1 - EFMK", "2 - XYZV" };
List<WebElement> options = new Select(driver.findElement(By.id("ClientReportingIssue"))).getOptions();
if (expectedIssues.length != options.size())
{
    // count of issues did NOT match
    System.out.println(
            "FAIL: CRI issues count failed. Expected: <" + expectedIssues.length + "> but there were <" + options.size() + ">");
}
else
{
    // count of issues matched
    System.out.println("Total Role: " + options.size());
    boolean pass = true;
    for (int i = 0; i < options.size(); i++)
    {
        if (!options.get(i).getText().equals(expectedIssues[i]))
        {
            pass = false;
            continue; // once it fails, quit the for loop
        }
    }
    if (pass)
    {
        System.out.println("PASS: CRI Information Matched");
    }
    else
    {
        System.out.println("FAIL: CRI Information NOT Matched");
    }
}