小编典典

如何使用带有Webdriver的Selenium Python打印下拉列表中存在的月份列表

selenium

下拉详细信息

 <select name="fromMonth">
 <option value="1">January
 </option><option value="2">February
 </option><option value="3">March
 </option><option value="4">April
 </option><option value="5">May
 </option><option value="6">June
 </option><option value="7">July
 </option><option value="8">August
 </option><option selected="" value="9">September
 </option><option value="10">October
 </option><option value="11">November
 </option><option value="12">December
 </option></select>

我想打印
一月
二月,
依此类推…


阅读 263

收藏
2020-06-26

共1个答案

小编典典

这将有助于:

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()

url='' //of webpage

driver.maximize_window()

driver.get(url)

listofelements=driver.find_elements(By.XPATH,'//*[@name="fromMonth"]/option') //to take all elements matching xpath

for i in range(len(listofelements)):
    print(listofelements[i].text) //print all elements of list
2020-06-26