I am trying to pull product assortment breakdowns from fashion retail websites using selenium chromedriver. However, I am getting stuck very early on because I cannot select the company's menu button
driver = webdriver.Chrome(PATH)
driver.get("https://www.zara.com/ca/")
driver.implicitly_wait(5)
menudd = driver.find_element(By.XPATH, '//*[@id="theme-
app"]/div/div/header/div/div[1]/button/svg')
menudd.click()
ERROR:
NoSuchElementException Traceback (most recent call last)
Input In [7], in <cell line: 8>()
4 driver.get("https://www.zara.com/ca/")
5 driver.implicitly_wait(5)
----> 8 menudd = driver.find_element(By.XPATH, '//*[@id="theme-
app"]/div/div/header/div/div[1]/button/svg')
9 menudd.click()`
CodePudding user response:
It's much better to use WebDriverWait
expected conditions explicit waits, not implicitly_wait
.
Also your locator is bad.
This worked for me:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver.get("https://www.zara.com/ca/")
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[aria-label='Open Menu']"))).click()
CodePudding user response:
if you want to locate svg in xpath, you should write in this way
//*[@id="theme-app"]/div/div/header/div/div[1]/button/*[name()='svg']