0

i use selenium chromedriver for make a program that automaticly go to nike.com and accept the cookie, but, for accept the cookie, the chromedriver must to find the cookie button with :

button = browser.find_element(By.CLASS_NAME,
"div[class='ncss-row']div[class='ncss-col-sm-12 ncss-col-md-6'] button[class='ncss-btn-primary-dark pt3-sm pb3-sm pt2-lg pb2-lg ta-sm-c u-full-width']"
)

but, when i start my program :

import webbrowser 
import undetected_chromedriver as uc
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
def main():
                                                                               
    browser = uc.Chrome()
                                                                            
    browser.get('https://www.nike.com/fr/snkrs-app?cp=24158993452_search_%7Csnkrs%7C10689554523%7C109060467241%7Ce%7Cc%7CFR%7Capp%7C508994633917&gclsrc=aw.ds&ds_rl=1252249&gclid=CjwKCAjwk_WVBhBZEiwAUHQCmV8yy66lssIN5EzoS0K8I4B1k9yk5kduxXy62w27SLfnChI_0U4UvBoC4P8QAvD_BwE')
                                                                                               
    sleep(8)
                                                                                              
    button = browser.find_element(By.CLASS_NAME, "div[class='ncss-row'] 
    div[class='ncss-col-sm-12 ncss-col-md-6'] button[class='ncss-btn-primary-dark pt3-sm pb3-sm pt2-lg pb2-lg ta-sm-c u-full-width']")
    button.click()
    sleep(100000)

if __name__ == '__main__':
    main()

So, when i start the program, he say that he not found the button, and i have tried a lot of solution, but i don't find the good program to do that.

This is a picture of the code of the button.

This is a picture of the code of the boutton.

User58
  • 17
  • 5
  • 1
    Somehow I don't face the cookie consent accessing the [URL](https://www.nike.com/fr/snkrs-app?cp=24158993452_search_%7Csnkrs%7C10689554523%7C109060467241%7Ce%7Cc%7CFR%7Capp%7C508994633917&gclsrc=aw.ds&ds_rl=1252249&gclid=CjwKCAjwk_WVBhBZEiwAUHQCmV8yy66lssIN5EzoS0K8I4B1k9yk5kduxXy62w27SLfnChI_0U4UvBoC4P8QAvD_BwE). Can you update the question with the text based HTML of the element? – undetected Selenium Jul 24 '22 at 22:24
  • Yes, it’s normal, Nike ask to accept the cookie just the first time, but Chromedriver use a invited session, so it’s ask every time to accept the cookies. – User58 Jul 24 '22 at 23:14
  • And for the question, I update it tomorrow, cause I live in France and it’s actually 1am. – User58 Jul 24 '22 at 23:14

2 Answers2

1

The following locator:

div[class='ncss-row']div[class='ncss-col-sm-12 ncss-col-md-6'] button[class='ncss-btn-primary-dark pt3-sm pb3-sm pt2-lg pb2-lg ta-sm-c u-full-width']

isn't a CLASS_NAME. It's a CSS_SELECTOR.

You need to change the line of accordingly:

button = browser.find_element(By.CSS_SELECTOR, "div[class='ncss-row'] div[class='ncss-col-sm-12 ncss-col-md-6'] button[class='ncss-btn-primary-dark pt3-sm pb3-sm pt2-lg pb2-lg ta-sm-c u-full-width']")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Okay, It’s surely for that, that the program are not working, I try every technique tomorrow (in France), so I say in 12 hours the solution, if it’s work. – User58 Jul 24 '22 at 23:20
0

so, i have find the solution, the css selector don't work and the id too (because it is the id of the text and not of the botton), so i have find an alternative :

import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
import time as t
import pandas as pd
from time import sleep

def main():
    browser = uc.Chrome()

    url = 'https://www.nike.com/fr/snkrs-app? 
cp=24158993452_search_%7Csnkrs%7C10689554523%7C109060467241%7Ce%7Cc%7CFR%7Capp%7C508994633917&gclsrc=aw.ds&ds_rl=1252249&gclid=CjwKCAjwk_WVBhBZEiwAUHQCmV8yy66lssIN5EzoS0K8I4B1k9yk5kduxXy62w27SLfnChI_0U4UvBoC4P8QAvD_BwE'

    browser.get(url)
    print("the action start to realised")
    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="gen-nav-commerce-header-v2"]/div[1]/div/div[2]/div/div[3]/div[1]/div[1]/button'))).click()
    print("the action are realised")
    sleep(1000)
    

if __name__ == '__main__':
    main()

I use the xpath, i reconmand it for find the boutton in general.

User58
  • 17
  • 5
  • Please mark your answer as the correct answer by pressing the checkmark. This way, the system knows your question has been answered. – Wouter Jul 26 '22 at 14:38