【发布时间】:2022-01-17 21:38:57
【问题描述】:
我正在尝试获取一些按钮标签的属性。
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')
shopList = driver.find_element(By.ID, "shopList")
try:
WebDriverWait(driver, 10).until(
EC.visibility_of_all_elements_located((By.XPATH, "//ul[@id='shopList']/li/div/button"))
)
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')
for item in li_items:
first = item.find_element(By.TAG_NAME, 'div')
second = first.find_element(By.TAG_NAME, 'button')
coord = second.get_attribute("onclick")
print(coord)
我正在等待加载所有按钮元素。但是,当我尝试打印所有按钮标签的onclick 属性时,它只打印前两个,然后抛出“NoSuchElementException:消息:没有这样的元素:无法定位元素”。但我不知道为什么。您可以通过转到“https://migroskurumsal.com/magazalarimiz/”并从最右侧的下拉菜单中选择“Migros”来查看 html。我恳请您的帮助。谢谢。
【问题讨论】:
标签: python html selenium webdriverwait