我正在使用wait method
查找元素,但它们给出的输出为空。错误出在哪里?
链接https://www.amazon.co.uk//dp/B094FZ1XFJ
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
PATH="C:\Program Files (x86)\chromedriver.exe"
url='https://www.amazon.co.uk//dp/B094FZ1XFJ'
driver =webdriver.Chrome(PATH)
driver.get(url)
item = dict()
try:
about_this_item_list = []
about_this_item_divs = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@id='featurebullets_feature_div']//ul//li//span")))
for div in about_this_item_divs:
about_this_dict = dict()
about_this_dict['about_this_item'] = div.text
about_this_item_list.append(about_this_dict)
item['about_this_item'] = about_this_item_list
except:
item['about_this_item'] = ''
print(item)
1条答案
按热度按时间dtcbnfnu1#
它应该是
visibility_of_all_elements_located()
,它返回元素列表。这将仅返回Web元素而不是Web元素列表。
更新:
您似乎需要滚动页面才能看到元素。尝试使用
presence_of_all_elements_located()
输出: