AttributeError: 类型对象 'By' 在 def CheckStock(myUrl,model) 中没有属性 'Class_Name'



我在阿迪达斯网站上找不到类。当我试图在html中查找类时,我遇到了上面的错误。我正在尝试用我的鞋机自动选择特定尺寸的过程。当我检查html代码时,我在代码中找到的类就是我在代码里写的。我是不是把课叫错了?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

def UrlGenwithSize(size,model,name):
base=580                   ####size of shoe
mysize=(size-4)*20         #### for a shoe of size 6.5
finalSize=base+mysize
Url="https://www.adidas.com/us/"+name+"/"+model+".html?forceSelSize="+model+"_"+str(finalSize)
return Url
def UrlGenProduct(name,model):
url="https://www.adidas.com/us/"+name+"/"+model+".html"
return url
def CheckStock(myUrl,model):
try:
driver = webdriver.Chrome(executable_path=r'C:Python39Libsite-packageswebdriver_botwebdriverschromedriver.exe')
driver.get(myUrl)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.Class_Name, "size-selector___2htsB")))  ###sets a time max of 10 secs and waits for the elements
username = driver.find_element_by_class_name('sizes___3Stmf fractions-decoration-reset___22Rwq')
buttons = username.find_elements_by_tag_name("button") ###get all the options into a list
buttonsList = []
for button in buttons:
buttonsList.append(button.get_attribute('innerHTML')) ###a list with sizes
for sizes in buttonsList:
if sizes.isdigit(): ###printing only if size in the list is a digit
print("Size" + sizes + "for" + model + "is available")
finally:
driver.quit()
url=UrlGenProduct("Kaptir Shoes","EE9513")
CheckStock(url,"EE9513")
size=int(input("Please enter size"))
myURL=UrlGenwithSize(6.5,"EE9513","Kaptir Shoes")
addToCart(myURL)

尝试大写字母

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "size-selector___2htsB")))

最新更新