Unable to extract content using selenium

I’m unable to print price of the selenium object using class attribute extracted from the page. Using the same class I can extract from some products, but not for all. What is the mistake I’m doing here?

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)

driver = webdriver.Chrome(options=chrome_options)


price_element = driver.find_element(By.CLASS_NAME, "a-offscreen")


I was expecting the print statement should provide the price of the product.

>Solution :

This selector

price_element = driver.find_element(By.CLASS_NAME, "a-offscreen")

selects multiple elements.

To get precisely price of the main product try using this

price_element = driver.find_element(By.ID, "corePriceDisplay_desktop_feature_div")

Leave a Reply