Java 下拉列表中的验证代码不是验证角色
整数计数=0; 字符串[]CRI={ “选择角色。”, “0-ABCD”, “1-EFMK”, “2-XYZV”}Java 下拉列表中的验证代码不是验证角色,java,selenium,selenium-webdriver,webdriver,Java,Selenium,Selenium Webdriver,Webdriver,整数计数=0; 字符串[]CRI={ “选择角色。”, “0-ABCD”, “1-EFMK”, “2-XYZV”} WebElement-box=CRIDrpDwn; 列表信息=box.findElements(按.tagName(“选项”)); System.out.println(“总角色:+Info.size()); 对于(int i=0;i
WebElement-box=CRIDrpDwn;
列表信息=box.findElements(按.tagName(“选项”));
System.out.println(“总角色:+Info.size());
对于(int i=0;i
附件CRI[\]\[1\]/>我将使用
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");
}
}
String[]expectedIssues={“选择客户端报告问题…”、“0-ABCD”、“1-EFMK”、“2-XYZV”};
List options=new Select(driver.findelelement(By.id(“ClientReportingIssue”)).getOptions();
if(expectedIssues.length!=options.size())
{
//问题计数不匹配
System.out.println(
“失败:CRI问题计数失败。预期:但有”);
}
其他的
{
//匹配问题的计数
System.out.println(“总角色:+options.size());
布尔传递=真;
对于(int i=0;i
请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。请参阅页面以获取澄清此问题的帮助。JeffC——实际上,我正试图用此代码验证下拉列表中的3个角色。但是验证元素是这样的。。0-xyz,1-ABC,2-KLM。所以我的问题是,这段代码没有验证下拉列表中的0-xyz,1-ABC,2-KLM元素。你能帮我解决这个问题吗?你还没有解释你的方案或发布HTML。我不确定我们将如何帮助您。JeffC——实际上,我正试图用这段代码验证下拉列表中的3个角色。但是验证元素是这样的。。0-xyz,1-ABC,2-KLM。所以我的问题是,这段代码没有验证下拉列表中的0-xyz,1-ABC,2-KLM元素。你能帮我解决这个问题吗Ejeffc--我在代码顶部添加了一个屏幕截图。。它包括html代码。如果你需要什么,请告诉我
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");
}
}