Python headless browser struggles with Nike.com form submission

I’m trying to do some automated testing on Nike.com using a headless browser in Python. But I’m hitting a wall with form submissions and logins. I’ve tried both mechanize and robobrowser libraries, but no luck so far.

Here’s a simplified version of what I’m attempting:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(options=chrome_options)

driver.get('https://www.nike.com')

login_form = driver.find_element_by_id('login-form')
email_field = login_form.find_element_by_name('email')
password_field = login_form.find_element_by_name('password')

email_field.send_keys('[email protected]')
password_field.send_keys('password123')

submit_button = login_form.find_element_by_class_name('submit-btn')
submit_button.click()

This code doesn’t work either. It seems like the website might be using some JavaScript tricks that are throwing off my automation attempts. Any ideas on what I might be missing or how to get around this issue?

I’ve encountered similar issues with Nike’s site when working on automation projects. Their site can be particularly challenging because of extensive JavaScript and anti-bot measures. In my experience, using Selenium with a full browser rather than headless mode often helps, as headless browsers tend to get detected more easily.

Adding delays between actions to simulate human behavior has also proven valuable, and using Selenium’s wait functions allows the page to load dynamically without relying on fixed sleeps. Finally, I found that handling CAPTCHAs and using a valid user agent, along with rotating IP addresses if possible, can make a significant difference. Remember to consider the terms of service before proceeding with automated testing.

yo, i feel ur pain with nike’s site. it’s a real headache for automation. have u tried using undetected_chromedriver? it’s like selenium on steroids for avoiding detection. also, maybe throw in some random waits between actions to make it look more human-like. good luck, mate!

Having worked extensively with web automation, I can attest that Nike’s site is notoriously difficult due to its sophisticated anti-bot measures. Your approach using Selenium is on the right track, but there are a few tweaks that might help. First, try adding a wait for the element to be clickable before interacting with it. Also, consider using a stealth plugin for Selenium to bypass bot detection. Here’s a snippet that’s worked for me:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

wait = WebDriverWait(driver, 10)
email_field = wait.until(EC.element_to_be_clickable((By.NAME, ‘email’)))
email_field.send_keys(‘[email protected]’)

This approach has yielded better results in my experience. Good luck with your automation project!