Matteo Possamai
Matteo Possamai

Reputation: 574

Selenium don't read text

I have just started studing selenium. I have this small code into I try to read the price of something in amazon.

    driver = webdriver.Chrome()
    link = "https://www.amazon.it/AMD-Ryzen-5-3600-Processori/dp/B07STGGQ18/ref=sr_1_2? 
    __mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&dchild=1&keywords=amd+ryzen+5&qid=1588259430&sr=8-2"
    driver.get(link)
    price = driver.find_elements_by_id("priceblock_ourprice")
    print(price.text)               
    driver.quit()

But the program say:

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

Now i noe that price is a list, but now, how can i take the price from amazon? Thank you

Upvotes: 1

Views: 42

Answers (1)

KunduK
KunduK

Reputation: 33384

find_elements_by_id() will return as list and list has no attribute text.

change it to find_element_by_id() which return as element.

price = driver.find_element_by_id("priceblock_ourprice")
print(price.text)  

Upvotes: 1

Related Questions