What you are trying is:
- in first iteration you click the first element and click the add to cart button
- in Second iteration you click the second element and tries to click the add to cart button using the same locator as you used in the first iteration
The below locator finds the first element that matches the locator "a.ajax_add_to_cart_button"
- As you are using the same locator for all the iteration, it always
finds the first element which is the add button of the first product.
- So in your second iteration, you are not trying to click the "add
item to cart" button of second product, but the first product itself. As add button of the first product is not visible, selenium
throws "not intractable exception"
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
for i in cart:
print(i.find_element_by_css_selector("h5").text)#just to see that loop went to next iteration
i.find_element_by_xpath("//span[@class='continue btn btn-default button exclusive-medium']//span").click()
Here instead of using
"a.product-name", I used
to find all the products. This locator finds all the li elements which have class name that contains
The new locator finds the parent element instead of just the description (entire product element "including image, description, and price).
now when you iterate cart, In 'i' you have a parent element with the
description, add button, etc as the child elements
So to get text we call i.find_elment("h5"), for add button we call i.find_elment("a.ajax_add_to_cart_button") etc. Here selelnium will not search the entire html to find the a.ajax_add button, but will search only for elements which are under the product we are interested in.