Cant login into Nike with python selenium

2.7k views Asked by At

I know there is already one other pretty similar question, but my is a bit different. The problem is, that you cant login into Nike by using Selenium. It worked along time for me, but somehow it stopped working. I was reading a bit about how to bypass that and came to the solution, to just use an older chrome version(I'm using chrome driver). That worked, how ever now its not again and Nike is again blocking the login. The old Version I was using, was 79. The new Version that did worked for me a long time ago and that is the newest Version right now is 90. This is my Code, that tried to login into Nike:

import time 
from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-blink-features")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options = chrome_options)
driver.get("https://www.nike.com/login")
time.sleep(2)
email = driver.find_element_by_xpath('//input[@type="email"]')
email.send_keys("THE-EMAIL")
password = driver.find_element_by_xpath('//input[@type="password"]')
password.send_keys("THE-PASSWORD")
button = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[7]/form/div[6]/input")
button.click()

Does someone knows why its blocking selenium? I mean manually I can Login, so its not because of the Account.

1

There are 1 answers

1
Pierre On

The solution given by colossatr0n in this thread Can a website detect when you are using Selenium with chromedriver? worked for me. Here is a partial copy, the idea is to replace cdc_ with another string in order not to be detected:

vim /path/to/chromedriver

After running the line above, you'll probably see a bunch of gibberish. Do the following:

Replace all instances of cdc_ with dog_ by typing :%s/cdc_/dog_/g. dog_ is just an example. You can choose anything as long as it has the same amount of characters as the search string (e.g., cdc_), otherwise the chromedriver will fail. To save the changes and quit, type :wq! and press return. If you need to quit without saving changes, type :q! and press return.

I also had to update the line to get the button:

 button = driver.find_element_by_xpath("/html/body/div[4]/div[1]/div[1]/div[1]/div[7]/form/div[6]/input")    

Selenium managed to login!