在您的第一个选项中,硒明确指出 Element应该是“ select”但为“ option”
,这意味着您在提供
xpathfor的
option同时仅
xpath希望选择。
不需要使用您提供的其他选项,只需使用以下第一个选项即可:-
Select elm = new Select(driver.findElement(By.id("type")));elm.selectByVisibleText("Date");要么
ByIndex
elm.selectByIndex(2);
要么
ByValue
elm.selectByValue("1");如果不幸的是您的第一个选项不起作用,我希望您使用第三个选项使用
JavascriptExecutor,如下所示:-
WebElement select = driver.findElement(By.id("type"));((JavascriptExecutor)driver).executescript("var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].text == arguments[1]){ select.options[i].selected = true; } }", select, "Date");希望它能帮助您… :)



