我正在尝试使用List从下拉列表中选择值,已经尝试使用Select但没有运气。这段代码对我来说很好但是它也在Catch块内。
以下是使用selenium选择下拉值的方法。
public static void selectStatusFromDropDownInUserManagement(WebDriver driver, String testCasename, String Status) throws ActionBotException
{
String val = null;
WebElement ele3 = null;
try {
ActionBot.click(driver, By.xpath(".//*[@data-id='status']"));
WebElement ele=ActionBot.findElement(driver, By.xpath(".//*[@class='dropdown-menu open']/ul"));
List<WebElement> columns= ele.findElements(By.tagName("li"));
System.out.println(columns.size());
for(WebElement ele2:columns)
{
ele3=ele2;
val=ele2.getText();
System.out.println(val);
if(val.contentEquals(Status))
{
System.out.println("value from excel is"+Status);
ele3.click();
}
}
} catch (Exception e)
{
logger.info("Unable to select a status in user management page");
ScreenShotUtil.takeScreenshot(driver, testCasename, "select Status
From Drop Down In User Management", false);
Assert.fail();
}
}