如何select 合适的产品尺寸?硒 - ChromeDriver
How to select the right size of a product? Selenium - ChromeDriver
我的代码:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
browser = webdriver.Chrome('C:/Users/rober/OneDrive/Skrivebord/bot/chromedriver')
# Graffik kort
browser.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
buyButton = False
while buyButton is False:
try:
addToCartBtn = addButton = browser.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button')
print("Varen er udsolgt")
time.sleep(1)
browser.refresh()
except:
addToCartBtn = addButton = browser.find_element_by_xpath('//*[@id="picker-trigger"]')
print("Varen er på Lager")
buyButton = True
while buyButton is True:
time.sleep(3)
accept = browser.find_element_by_id('uc-btn-accept-banner')
browser.execute_script("arguments[0].click();", accept)
element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="picker-trigger"]')))
element.click();
我的错误:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="uc-btn-accept-banner"]"}
我的问题是我想获得欧盟尺寸的 51.5 码,但我不知道 select 那个尺寸的代码和 CLASS 尺寸。
如果有人知道解决方案,请发表评论,因为我真的需要一些帮助才能找到正确的解决方案。
到select尺寸为51.5你需要归纳 for the and you can use the following :
代码块:
driver.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.uc-btn#uc-btn-accept-banner"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Vælg størrelse']"))).click()
driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))).click()
浏览器快照:
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
我的代码:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
browser = webdriver.Chrome('C:/Users/rober/OneDrive/Skrivebord/bot/chromedriver')
# Graffik kort
browser.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
buyButton = False
while buyButton is False:
try:
addToCartBtn = addButton = browser.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button')
print("Varen er udsolgt")
time.sleep(1)
browser.refresh()
except:
addToCartBtn = addButton = browser.find_element_by_xpath('//*[@id="picker-trigger"]')
print("Varen er på Lager")
buyButton = True
while buyButton is True:
time.sleep(3)
accept = browser.find_element_by_id('uc-btn-accept-banner')
browser.execute_script("arguments[0].click();", accept)
element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="picker-trigger"]')))
element.click();
我的错误:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="uc-btn-accept-banner"]"}
我的问题是我想获得欧盟尺寸的 51.5 码,但我不知道 select 那个尺寸的代码和 CLASS 尺寸。
如果有人知道解决方案,请发表评论,因为我真的需要一些帮助才能找到正确的解决方案。
到select尺寸为51.5你需要归纳
代码块:
driver.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.uc-btn#uc-btn-accept-banner"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Vælg størrelse']"))).click() driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']")))) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))).click()
浏览器快照:
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC