0

I've been trying to click a button using selenium but it keeps saying that the element isn't interactable even though it is visible on screen and I can manually click it. I've tried webdriverwait, implicitly wait and many other solutions but none seem to work. Please can anyone offer a solution. I've attached the buttons code and my own code.

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options 
browser = webdriver.Chrome('')
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-popup-blocking")
browser.implicitly_wait(10)
browser.get('https://www.aldi.co.uk/kirkton-house-high-back-desk-chair/p/709360437078000')
browser.maximize_window()
buybutton = False

while not buybutton:
    try:
        addToCartBtn = addButton = browser.find_element_by_class_name('disabled')
        print("Button isn't ready yet.")
        time.sleep(1)
        browser.refresh()
    except:
        time.sleep(2)
        addToCartBtn = addButton = browser.find_element_by_xpath('//*[@id="addToBasketButton"]')
        addToCartBtn.click()
        
     
        buybutton = True

<div class="product-details__selectButton" data-component="productAdder">
                <span class="js-sticky-atc__anchor"></span>
                <button class="product-details__cta js-product-cta button button--big button--rectangle button--transactional" type="submit" data-sku="709360437078000" data-limit="" data-limit-error="Sorry, you can only purchase 10 of this item." data-stock="inStock" data-stock-error="Out of stock" data-stock-pack-cta1="true" data-stock-pack-cta2="true" data-csrftoken="207d2b40-a785-40b6-89cd-987eba44a31c" data-is-buy-online="true" data-api="/api/cart/add" data-purchase-disabled="" aria-label="Add Kirkton House High Back Desk Chair to the basket" aria-controls="minicart-trigger" id="addToBasketButton">
                    <span class="js-product-cta-label" data-product-added="PRODUCT ADDED">
                        ADD TO BASKET</span>
                    <svg class="icon icon--basket">
                        <use xlink:href="/assets/8b290d70406f652780c7cc1c72fe4a88/dist/icons/sprite.symbol.svg#basket"></use>
                    </svg>
                </button>
            </div>

2 Answers 2

1

Try this xpath:

driver.find_element_by_xpath(".//ul[contains(@class,'errors')]//following::form[contains(@class,'product-form')]//button[@id='addToBasketButton']").click()
Sign up to request clarification or add additional context in comments.

Comments

0

With the xpath you are using with ID addToBasketButton has two web elements :

Use this CSS_SELECTOR Instead :

ul.product-details__list.product-details__list--errors+form div.product-details__selectButton button

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.