-1

I am trying to make a stock bot that checks if something is in stock and when I try to use:

if ATC.isDisplayed():

I get the error:

AttributeError: 'list' object has no attribute 'isDisplayed'

My whole code:

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} ||')

If anyone could help that would be very helpful, I've been trying to figure this out for ages.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Please supply the expected [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) (MRE). We should be able to copy and paste a contiguous block of your code, execute that file, and reproduce your problem along with tracing output for the problem points. This lets us test our suggestions against your test data and desired output. This code is *not* minimal, and it dies on your external references. – Prune Feb 18 '21 at 00:01
  • We expect you to perform basic diagnosis to include with your post. At the very least, print the suspected values at the point of error and trace them back to their sources. In many cases, doing this basic diagnosis will show you where the problem lies, and you won't need Stack Overflow at all. The error message is quite clear: ATC is a list. You need to trace how it got to be a list, instead of what you expected. – Prune Feb 18 '21 at 00:02
  • @Prune I'm very sorry, I'm new to coding and Python. Could you help me out and let me know how it became a list? I don't even fully know what that means, im sorry :( – F Inchatbois Feb 18 '21 at 00:05
  • See this [lovely debugging site](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) for help. Giving you a personal tutorial on debugging is very much out of scope here. – Prune Feb 18 '21 at 00:07
  • @Prune Could you atleast let me know what its got to do with? – F Inchatbois Feb 18 '21 at 00:11
  • Find_element instead of find_elements. You use isdisplayed on a single element instead of a list. – Arundeep Chohan Feb 18 '21 at 01:04

2 Answers2

0

ATC is of type list as find_elements_by_css_selector() would return a list.

However, there is no method/attribute as isDisplayed() but is_displayed() and is applicable for WebElement only.


Solution

You need to iterate through the list of elements identified through:

OOS = driver.find_elements_by_css_selector("#product-actions > div.oos.oos-no-alt.border.space-b > strong")

possibly using a for() loop.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

This will help beginners and you would have made mistake in selecting the wrong function

would have selected this one

user_name = driver.find_elements_by_name()

you need to select this one

user_name = driver.find_element_by_name()

In simple words remove s from "elements"

nullptr
  • 3,701
  • 2
  • 16
  • 40
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 27 '22 at 16:23