當getoption
用於從下拉菜單檢索值時,硒List<WebElement>
返回零。硒列表<WebElement>總是返回空值
代碼片段:
public class FaceBookdropDownMenu {
public static void main(String[] args) throws InterruptedException {
System.getProperty("webdriver.gecko.driver", "//usr//local//bin//geckodriver 6");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
WebElement month_dropdown = driver.findElement(By.id("month"));
//return a list of month names
System.out.println(month_dropdown.getText());
List<WebElement> month_lists = driver.findElements(By.id("month"));
int total_month= month_lists.size();
// returns 1 instead of 12
System.out.println("Total month count is"+ total_month);
for(WebElement ele:month_lists) {
String month_name = ele.getText();
System.out.println("Months are:"+ month_name);
}
}
}
==================================== ================================== 我用的是getOptions()
,但它不工作,要麼
WebElement month_dropdown =driver.findElement(By.id("month"));
System.out.println(month_dropdown.getText());
Select month_dd = new Select(month_dropdown);
List <WebElement> month_lists = month_dd.getOptions();
int total_month= month_lists.size();
//Zero is returned instead of 12
System.out.println("Total month count is"+ total_month);
for(WebElement ele:month_lists) {
String month_name = ele.getText();
System.out.println("Months are:"+ month_name);
}
究竟是你想做些什麼?我覺得你並不遙遠,但很難理解你想做什麼。 – ProgrammersBlock
我想顯示月份總數(12)並列出月份名稱,1月至12月 – Ant
請發佈相關HTML – JeffC