我无法使用特定 URL 在 Python Selenium 中找到任何元素

问题描述 投票:0回答:1

我正在尝试开发一个代码来获取网站每个产品中的所有成分,但是当我尝试使用“driver.find_element”时,我的 Selenium 找不到任何元素。

我用过:

chromedrive_path = 'MY_PATH'
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = chromedrive_path
chrome_options.add_argument('--headless') 
#chrome_options.add_argument('--no-sandbox')

url = 'https://www.boticario.com.br/'
chrome = webdriver.Chrome(options=chrome_options)
chrome.get(url)
sleep(3)
chrome.find_element(By.XPATH, "/html/body/header/nav/ul/li[13]/a").click()

还有:

button = WebDriverWait(chrome, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/header/nav/ul/li[13]/a")))
button.click()

我也已经尝试了许多不同的元素,但它们都返回了 NoSuchElementException 错误(或 TimeoutException,对于第二个代码)。

python html selenium-webdriver web-scraping selenium-chromedriver
1个回答
0
投票

您确定使用正确的 XPATH 吗?无论如何,最好找到 By.ID 或 By.CSS_SELECTOR 的元素

© www.soinside.com 2019 - 2024. All rights reserved.