且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Selenium和python从下拉列表中获取值列表

更新时间:2023-08-26 12:30:22

使用根据***做法,您可以添加 WebDriverWait expected_conditions 如下:

As per the best practices, you can add WebDriverWait and expected_conditions as follows:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.ui import Select

locator = "/html/body/div[3]/div[8]/div[2]/div[1]/div[3]/div/div/select[1]"
botton_to_select = WebDriverWait(driver, 10).until((EC.element_to_be_clickable, (By.XPATH, locator)))
botton_to_select.click()
select = Select(browserdriver.find_element_by_xpath(locator))
for item in select.options:
    print(item.get_attribute('innerText'), item.get_attribute('value'))

希望这对您有所帮助!