有几种方法可以从下拉列表中选择元素。以下是其中一些,您可以将它们保留为常见的下拉操作并调用您需要的任何方法。
//select the dropdown using "select by visible text"
public static void dropDownSelectByText(WebElement webElement, String VisibleText){
Select selObj=new Select(webElement);
selObj.selectByVisibleText(VisibleText);
}
//select the dropdown using "select by index"
public static void dropDownSelectByIndex(WebElement webElement, int IndexValue){
Select selObj=new Select(webElement);
selObj.selectByIndex(IndexValue);
}
//select the dropdown using "select by value"
public static void dropDownSelectByValue(WebElement webElement, String Value){
Select selObj=new Select(webElement);
selObj.selectByValue(Value);
}
您可以调用上述方法,例如
CommonPageOperations.dropDownSelectByValue(selectSubClientFromDropDownXpath,strSubClientName);
仅当鼠标移动到特定位置时才会出现下拉列表,然后您还必须使用操作
public void mouseMoveToExpandIcon(){
Actions action = new Actions(driver);
action.moveToElement(expandButtonXpath).perform();
}