使用Selenium Python在多个选择框中一次选择所有选项

时间:2019-04-28 12:56:22

标签: python selenium selenium-webdriver web-scraping webdriver

我有40个选项的“选择”框。选择全部40个选项后,我想下载文件。现在,我使用循环来迭代每个元素,然后下载文件。由于我使用的是 Firefox Web驱动程序,硒和Python ,因此在Chrome Web驱动程序中快速运行非常耗时。但是文件不会在Chrome网络驱动程序中以无头模式下载。因此,我决定使用Firefox。我尝试了其他堆栈溢出答案,但未能实现我的目标。

所以有人可以告诉我如何通过选择第一个选项然后拖动到最后一个选项来一次选择下拉菜单中的所有选项吗?

编辑: 我想一次选择所有项目,而不是手动一次。

目前我正在这样做:-

dropdown_options = select_box.options

select_box = Select(driver.find_element_by_xpath("//select[@id='shipStatusIdList']"))
x=[select_box.select_by_index(ele_index) for ele_index in range(len(dropdown_options)) ]


    <option value="AT_STATION">At Station</option>   
                <option value="AT_WRONG_STATION">At Wrong Station</option>   
                <option value="BETWEEN_FC_AND_STATIONS">Between FC/SC and Stations</option>   
                <option value="BETWEEN_STATIONS">Between Stations</option>   
                <option value="CANCELLED">Cancelled</option>   
                <option value="CASH_AT_STATION">Cash at Station</option>   
                <option value="CASH_RECEIVED_IN_THE_BANK">Cash in Bank</option>   
                <option value="CASH_IN_TRANSIT_BETWEEN_STATION_AND_BANK">Cash in transit to bank</option>   
                <option value="CASH_IN_ASSOCIATE">Cash with Associate</option>   
                <option value="DELAYED">Delayed</option>   
                <option value="DELAYED_AT_STATION">Delayed / At Station</option>   
                <option value="DELIVERED">Delivered</option>   
                <option value="DELIVERY_ATTEMPTED">Delivery Attempted</option>   
                <option value="DEPARTED_FOR_FC">Departed For FC/SC</option>   
                <option value="DROPPED_AT_ORDT">Dropped At ORDT</option>   
                <option value="DROPPED_AT_STORE">Dropped At Store</option>   
                <option value="HOLD_FOR_CUSTOMER_REQUEST">Hold for Customer Request</option>   
                <option value="HOLD_FOR_PICKUP">Hold for Pickup</option>   
                <option value="HOLD_FOR_REDELIVERY">Hold for Redelivery</option>   
                <option value="IN_TRANSIT_TO_ORDT">In Transit To ORDT</option>   
                <option value="IN_TRANSIT_TO_STORE">In Transit To Store</option> 
.
.
.
.

共有40个选项。

enter image description here

0 个答案:

没有答案