# import webdriver
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import WebDriverException
# create webdriver object
driver = webdriver.Firefox()
url = "https://www.zalando.no/tommy-jeans-tjm-essential-down-vest-vest-court-blue-tob22t06j-k11.html"
driver.get(url)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="uc-btn-accept-banner"]'))).click()
driver.find_element(By.XPATH, "/html/body/div[4]/div/div[1]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[2]/button/span").click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"/html/body/div[9]/div/div[3]/div/form/div/div[4]/div/label/span/div/span"))).click()
I'm trying to create a sneaker bot for fun. When I click to select shoes size I can't locate the element for some reason.
CodePudding user response:
wait.until(EC.element_to_be_clickable((By.XPATH,"(//span[.='XS'])[1]"))).click()
Should work for the XS size if you want since most of the elements seem dynamic.
CodePudding user response:
You are using absolute xpath
, please switch to relative path
.
Also, it's a good practice to create object of WebDriverWait
once and then use the reference in other places in your code.
driver = webdriver.Firefox()
driver.maximize_window()
wait = WebDriverWait(driver, 30)
url = "https://www.zalando.no/tommy-jeans-tjm-essential-down-vest-vest-court-blue-tob22t06j-k11.html"
driver.get(url)
try:
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='uc-btn-accept-banner']"))).click()
except:
pass
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[aria-label='Legg i handlekurven']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='L']"))).click()
Imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC