I’m encountering a peculiar issue when using Selenium in a Python script to interact with a webpage. Specifically, I’m trying to scrape data from this webpage.
Python code:
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
link = "https://www.homedepot.com/p/Ejoy-20-in-H-x-20-in-W-GorgeousHome-Artificial-Boxwood-Hedge-Greenery-Panels-Milan-12-pc-Milan-12pc/314160722"
# Launch a Chrome browser
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
driver.get(link)
# Wait for the page to load
time.sleep(3)
# Find the drop-down element
dropdown = driver.find_element(By.XPATH, "//*[@id='product-section-specifications']")
dropdown.click()
# Attempt to find elements within the drop-down
headers = dropdown.find_elements(By.CSS_SELECTOR, "div[class='kpf__name']")
print(len(headers))
print(headers[0].text)
The issue I’m encountering is that while the page appears to load properly, certain elements, specifically those within a drop-down, disappear before I can interact with them. Strangely, when I manually open the same webpage in my personal Chrome browser, everything loads and remains visible as expected.
I initially suspected that a script might be removing the content, but upon comparing the console output between Selenium and my personal browser, they show the same “error” output, leading me to believe that this might not be the cause of the issue.