Amazon web scraping (hidden element) after redirect to cart page (python, selenium)


How can I get the hidden information from cart when I update the items in cart to 999(itrack method). The class of the span is a-size-base. I use python and selenium(I attached the program)
So my program will open a product page link, click on add to cart, redirect to cart page and now I want to extract the information in the span with class a-size-base. You can see that span tag if you update the items in the cart to 999 and click enter. It will appear an alert span. I want to extract that information.
I will appreciate any help.

from selenium import webdriver
from time import sleep

url = ""

driver = webdriver.Chrome(executable_path="C:\UsersAndreiDownloadschromedriver_win32chromedriver.exe")






items_cart = driver.find_element_by_xpath('//div[@class="a-alert-content"]/span')

print driver.execute_script("return arguments[0].innerHTML",items_cart)
Asked By: ryy77



Here is how I changed the number of items in the cart

# update the quantity 
from selenium.webdriver.common.keys import Keys
quantity_xpath = '//*[@id="activeCartViewForm"]/div[2]/div/div[4]/div/div[3]/div/div/input'
quantity_el = driver.find_element_by_xpath(quantity_xpath)
quantity_el.send_keys("999" + Keys.ENTER)

Now the quantity is updated, the alert message should appear. It seems while using your xpath you for item_cart you are picking an alert for delivery status so you have to narrow down you xpath string to be more specific.

items_cart = driver.find_element_by_xpath('//*[@class="sc-list-item-content"]//*[@class="a-alert-content"]/span')
print items_cart.text
Answered By: hashmuke
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.