String[] expected = new String[10];
//{"Acapulco","Frankfurt","London","New York","Paris","Portland","San Francisco","Seattle","Sydney","Zurich"};
expected[0] = "Acapulco";
expected[1] = "Frankfurt";
expected[2] = "London";
expected[3] = "New York";
expected[4] = "Paris";
expected[5] = "Portland";
expected[6] = "San Francisco";
expected[7] = "Seattle";
expected[8] = "Sydney";
expected[9] = "Zurich";
List<WebElement> allOptions = driver.findElements(By.name("fromPort"));
// match the fromPort list value against the expected Array
for (int i = 0 ; i < (expected.length) && i < allOptions.size(); i++) {
String optionValue = allOptions.get(i).getAttribute("value");
if (optionValue.equals(expected[i])) {
System.out.println("PASSED on: " + optionValue + " we had: "+ expected[i]);
}
else {
System.out.println("FAILED on: " + optionValue + " we expected: " + expected[i]);
}
}
//close Firefox
driver.close();
當執行循環只會輪一次,然後它的存在......因此,它執行: 傳遞:阿卡普爾科我們有:阿卡普爾科 然後退出循環...For循環不僅通過一次
My Other Comment新所有這一切的Java和硒....
我假設它的東西做的僅是1大小;:
這是從我的其他評論下面就但不知道如何增加/克服這個
HTML片段添加在意見中的要求:
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" size="2">
<b>
Departing
From:
</b>
</font>
</td>
<td>
<select name="fromPort">
<option value="Acapulco"></option>
<option value="Frankfurt"></option>
<option value="London"></option>
<option value="New York"></option>
<option value="Paris"></option>
<option value="Portland"></option>
<option value="San Francisco"></option>
<option value="Seattle"></option>
<option value="Sydney"></option>
<option value="Zurich"></option>
</select>
您是否嘗試過打印list allOptions的大小? –
是的它的打印1 - 這是什麼讓我相信多數民衆贊成在罪魁禍首 - 但如上所述不能確定這一點。但是,它又可能是1作爲「循環中的第一個」? – xTNAx
嘗試在循環之前打印,儘管結果相同。將需要html片段。 –