以下代码无法打印下拉列表
public class listAssignment {
public void assigntest(){
System.setProperty("webdriver.gecko.driver",
"C:/Users/Downloads/geckodriver-v0.16.1-win64/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
WebElement month_dropdown = driver.findElement(By.id("month"));
List<WebElement> options = month_dropdown.findElements(By.id("month"));
for (WebElement option : options) {
String month_name = option.getText();
System.out.println("output====="+month_name );
}
答案 0 :(得分:0)
我认为你的代码几乎可以正常工作。这是我用python
测试的版本from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.facebook.com/")
driver.maximize_window()
WebElement_month_dropdown = driver.find_element_by_id('month').text.splitlines()
print(WebElement_month_dropdown)
for month in WebElement_month_dropdown:
print ("output=====" + month)
答案 1 :(得分:0)
添加了选择类(选择月份=新选择(month_dropdown),现在工作正常,谢谢..