I'm not sure what is the issue in your case using Select
class, but if you want an alternate solution to get rid from this error, you can try using JavascriptExecutor
as below :-
public static String selectByIndex(WebDriver driver, WebElement select, int index) {
String javaScript = "var select = arguments[0]; "
+ "select.options[arguments[1]].selected = true;"
+ "return select.selectedOptions[0].text";
return (String) ((JavascriptExecutor) driver).executeScript(javaScript, select, index);
}
WebElement select = expedia.findElement(By.id("lineOfBusiness"));
Assert.assertEquals(selectByIndex(expedia, select, 1), "HWW Sales");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…