我正在尝试制作一个库存机器人,用于检查是否有库存,以及何时尝试使用:
if ATC.isDisplayed():
我得到一个错误:
AttributeError: 'list' object has no attribute 'isDisplayed'
我的全部代码:
import time
import asyncio
import colorama
import subprocess
from colorama import Fore, Back, Style
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.expected_conditions import presence_of_element_located
driver = webdriver.Chrome(
executable_path=r'C:\Users\Joe mama\Desktop\app\chromedriver.exe')
colorama.init(autoreset=True)
driver.get("https://www.currys.co.uk/gbuk/computing-accessories/components-upgrades/graphics-cards/msi-geforce-rtx-3060-ti-8-gb-gaming-x-trio-graphics-card-10219250-pdt.html")
driver.maximize_window()
Name = driver.find_elements_by_css_selector(
"#content > div.product-page > section > div.to-print > h1 > span:nth-child(2)")
Price = driver.find_elements_by_css_selector(
"#product-actions > div.amounts > div > div > span.ProductPriceBlock__Price-kTVxGg.QWqil")
Link = driver.find_elements_by_tag_name("a")
OOS = driver.find_elements_by_css_selector(
"#product-actions > div.oos.oos-no-alt.border.space-b > strong")
ATC = driver.find_elements_by_css_selector(
"#product-actions > div.channels.space-b > div.space-b.center > button")
while True:
try:
if OOS.isDisplayed():
print(colorama.Fore.RED +
f"|| {Name[0].text} || Out Of Stock || {Price[0].text} ||")
driver.refresh()
except:
if ATC.isDisplayed():
print(colorama.Fore.GREEN +
f'|| {Name[0].text} || IN STOCK || {Price[0].text} ||')
如果有人能帮上忙的话,那将是非常有帮助的,我一直在努力解决这个问题
ATC
是list类型,因为find_elements_by_css_selector()将返回list但是,没有方法/属性作为
isDisplayed()
,而是作为is_displayed(),并且只适用于WebElement解决方案
您需要遍历通过以下方式标识的元素列表:
可能使用
for()
循环相关问题 更多 >
编程相关推荐