【发布时间】:2022-01-15 04:03:20
【问题描述】:
我正在尝试在 ul 中获取 li 项目。这是我的代码:
driver.get('https://migroskurumsal.com/magazalarimiz/')
try:
select = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, 'stores'))
)
print('Dropdown is ready!')
except TimeoutException:
print('Took too much time!')
select = Select(driver.find_element(By.ID,'stores'))
select.select_by_value('2')
try:
shopList = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "shopList"))
)
print('Shoplist is ready!')
except TimeoutException:
print('Took too much time!')
driver.quit()
print(shopList.get_attribute("class"))
li_items = shopList.find_elements(By.TAG_NAME,'li')
print(len(li_items))
我成功找到了 id=shopList 的 ul 元素。然后我尝试使用 find_elements(By.TAG_NAME) 获取 ul 下的所有 li 元素。我还尝试了 find_elements(By.CLASS_NAME),但是 len(li_items) 始终为 0。我请求您的帮助。谢谢。
【问题讨论】: