0

I am trying to log on to Target's website using Selenium in Python with the Chrome WebDriver..

When I am prompted to log in, I use the following code:

self.browser.find_element_by_name("password").send_keys(pw)
self.browser.find_element_by_id("login").submit()

After the field is submitted, I am presented with this error in the DOM:

DOM Error Alert

..and this in the console:

401 Error

Note:

I have tried logging in with Selenium on Instagram, and it works.. So I know it has something to do with the structure of Target's website. Has anyone run into this issue before?

Thanks!

1 Answers1

0

So I originally tried solving this issue using Chrome, but could not figure out why the page would not precede after entering the login data. I thought maybe the page was protected by some bot software, but could not find any proof.

I decided to try Safari on my MAC, and actually had success. See the below code:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Safari(executable_path='/usr/bin/safaridriver')
driver.get('https://www.target.com/')
action = ActionChains(driver)
driver.find_element(By.XPATH, '//*[@id="account"]').click()
WebDriverWait(driver, 30).until(ec.presence_of_element_located((By.XPATH, '//*[@id="accountNav-signIn"]')))
action.send_keys(Keys.ENTER)
action.perform()
WebDriverWait(driver, 10).until(ec.presence_of_element_located((By.XPATH, '//h2[@class="sc-hMqMXs sc-esjQYD eXTUDl"]')))
driver.find_element(By.ID, 'username').click()
driver.find_element(By.ID, 'username').send_keys('foo')
time.sleep(5)
driver.find_element(By.ID, 'password').click()
driver.find_element(By.ID, 'password').send_keys('bar')
time.sleep(5)
driver.find_element(By.XPATH, "//button[@id=\'login\']").send_keys(Keys.ENTER)
time.sleep(10)
driver.quit()

You will notice some time.sleeps which I am using to slow the program down (you can take these out).

I also tried on FireFox and Edge, but had the same problems as Chrome.

Conclusion, it seems there could be some sort of bot protection which is blocking you from using Chrome (also Edge and FireFox). Given these webdrivers are being detected as automated. Safari (I believe) does not get detected as such.

I would also suggest reading through the below post, it may offer more insight. Website navigates to no-access page using ChromeDriver and Chrome through Selenium probably Bot Protected

Dharman
  • 30,962
  • 25
  • 85
  • 135
Ryan Burch
  • 500
  • 4
  • 11