3 回答
TA贡献1820条经验 获得超9个赞
您可以等到可点击父项,然后出现选项。您可以按value属性选择选项
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#other code
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#s"))).click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#s [value="65382"]'))).click() #Possibly just [value="65382"]
TA贡献1825条经验 获得超4个赞
您可以等到可点击父项,然后出现选项。您可以按value属性选择选项
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#other code
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#s"))).click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#s [value="65382"]'))).click() #Possibly just [value="65382"]
TA贡献1772条经验 获得超5个赞
您可以使用 xpath 并直接单击该选项。
driver.find_element_by_xpath('//select[@id="s"]//option[normalize-space(.)="XLarge"]').click()
添加回答
举报