Selenium button not being clicked but is being highlighted

391 Views Asked by At

What I'm trying to do is making nike product auto buyer the problem is after selecting size it doesn't let me click through selenium I even tried to click manually but nothing pops up this is my code where I try to click (not full code):

from selenium import webdriver
from selenium.common.exceptions import JavascriptException
from selenium.webdriver import ChromeOptions
import re
from bs4 import BeautifulSoup
import requests
import json
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import os

user = os.environ['USERNAME']
snkrsurl = "https://www.nike.com/t/air-zoom-pegasus-38-womens-running-shoe-wide-gg8GBK/CW7358-500" #input("Please input your SNKRS url \n")
size = float(input("Please input size \n"))
options = ChromeOptions()
options.add_experimental_option('excludeSwitches',['enable-logging'])
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("detach",True)
options.add_argument("--disable-notifications")

chrome = webdriver.Chrome(options=options)
if "https://" in snkrsurl:
    pass
elif "http://" in snkrsurl:
    pass
else:
    snkrsurl = "http://"+snkrsurl

chrome.get(snkrsurl)
with requests.Session() as session:
    soup = BeautifulSoup(session.get(snkrsurl).text, features="lxml")
script = soup.find("script", string=re.compile('INITIAL_REDUX_STATE')).string
redux = json.loads(script[script.find('{'):-1])
products = redux["Threads"]["products"]
wait = WebDriverWait(chrome, 15)
def step1(i,v):
    for key, product in products.items():
        if float(product["skus"][i]["nikeSize"]) == v:
            print("Found")
            if v.is_integer():
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="gen-nav-footer"]/nav/button'))).click()
                wait.until(EC.element_to_be_clickable((By.XPATH, "//*[text()='{}']".format(int(v))))).click()
                chrome.execute_script("window.scroll(0,609)")
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[text()="Add to Bag"]'))).click()
                break
            else:
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="gen-nav-footer"]/nav/button'))).click()
                wait.until(EC.element_to_be_clickable((By.XPATH, "//*[text()='{}']".format(v)))).click()
                e = chrome.find_element_by_css_selector("#floating-atc-wrapper > div > button.ncss-btn-primary-dark.btn-lg.add-to-cart-btn")
                chrome.execute_script("arguments[0].scrollIntoView(true);")
                e.click()
                break
        else:
            pass
for i,v in products.items():
    global length 
    length = len(v['skus'])
    break
for i in range(length):
    length -=1
    step1(length,size)

I use window.scroll to go to that element because if I don't it throws error saying element is not interactable and yes checkout is being only clickable from real chrome. Thanks

0

There are 0 best solutions below