0

Picture of the screen it stays on forever:

Picture of the screen it stays on forever

I am having trouble getting Selenium to login to Costco.com. It basically freezes at the login screen and won't proceed to the next screen.

from selenium import webdriver;
from selenium.webdriver.support.ui import Select;
from selenium.webdriver.common.keys import Keys;
from selenium.webdriver.common.by import By;
import time;

browser = webdriver.Chrome()
browser.get('https://www.costcobusinessdelivery.com/LogonForm?URL=%2f')

email = browser.find_element_by_css_selector('#logonId')
email.click()
email.send_keys('my_email')

password = browser.find_element_by_css_selector('#logonPassword_id')
password.click()
password.send_keys('my_password')

zipcode = browser.find_element_by_css_selector('#deliveryZipCode')
zipcode.click()
zipcode.send_keys('my_zipcode')


login = browser.find_element_by_css_selector('#sign_in_button')
login.click()

After a few minutes of Selenium sitting there it then pops out the traceback. I've tried using beautifulsoup4 to login and pass the data back to Selenium but I 'm not sure if this works. So I first have to navigate to the page I need in Selenium then parse the data with BS4.

TimeoutException                          Traceback (most recent call last)
<ipython-input-80-ddf2d5259794> in <module>
      1 login = browser.find_element_by_css_selector('#sign_in_button')
----> 2 login.click()

C:\ProgramData\Anaconda\lib\site-packages\selenium\webdriver\remote\webelement.py in click(self)
     78     def click(self):
     79         """Clicks the element."""
---> 80         self._execute(Command.CLICK_ELEMENT)
     81 
     82     def submit(self):

C:\ProgramData\Anaconda\lib\site-packages\selenium\webdriver\remote\webelement.py in _execute(self, command, params)
    631             params = {}
    632         params['id'] = self._id
--> 633         return self._parent.execute(command, params)
    634 
    635     def find_element(self, by=By.ID, value=None):

C:\ProgramData\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

C:\ProgramData\Anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):


TimeoutException: Message: timeout
  (Session info: chrome=77.0.3865.75)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
jest3rz
  • 21
  • 5
  • This code fills in the email, password, and zipcode fields, but then doesn't submit the form. Presumably there is a "Log In" button somewhere; you should add code to click on that. – John Gordon Sep 20 '19 at 19:23
  • Sorry, I had this line of code in there but I forgot to post it. It just hangs on the loading screen and won't go past it to the next screen. – jest3rz Sep 20 '19 at 19:28

2 Answers2

1

If the ID is available please use the ID and try out below example.

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

usernameStr = 'putYourUsernameHere'
passwordStr = 'putYourPasswordHere'
zipStr ='putZipCode'

browser = webdriver.Chrome()
browser.get(('https://www.costcobusinessdelivery.com/LogonForm?URL=%2f'))



username = browser.find_element_by_id('logonId')
username.send_keys(usernameStr)

password= browser.find_element_by_id('logonPassword_id')
password.send_keys(passwordStr)

zip= browser.find_element_by_id('logonPassword_id')
zip.send_keys(zipStr)



signInButton = browser.find_element_by_id('sign_in_button')
signInButton.click()
stacktome
  • 790
  • 2
  • 9
  • 32
  • It still sits there at the loading screen like it is trying to access the website but it doesn't go through. At the bottom of the screen it says waiting for www.costcobusinessdelivery.com. However, if I open a new browser outside of selenium and enter the information exactly the same it logs in no problem. – jest3rz Sep 20 '19 at 20:34
0

To login in to Costco.com through the url https://www.costcobusinessdelivery.com/LogonForm?URL=%2f you need to to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • css_selector:

    driver.get("https://www.costcobusinessdelivery.com/LogonForm?URL=%2f")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#logonId"))).send_keys("est3rz@stackoverflow.com")
    driver.find_element_by_css_selector("input#logonPassword_id").send_keys("my_password")
    driver.find_element_by_css_selector("input#deliveryZipCode").send_keys("54321")
    driver.find_element_by_css_selector("input#sign_in_button").click()
    
  • xpath:

    driver.get("https://www.costcobusinessdelivery.com/LogonForm?URL=%2f")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='logonId']"))).send_keys("est3rz@stackoverflow.com")
    driver.find_element_by_xpath("//input[@id='logonPassword_id']").send_keys("my_password")
    driver.find_element_by_xpath("//input[@id='deliveryZipCode']").send_keys("54321")
    driver.find_element_by_xpath("//input[@id='sign_in_button']").click()
    
  • Browser Snapshot:

costco

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • the problem is not the login, the login information enters correctly and selenium clicks the login button. It's that once the login button is clicked it just continuously loads forever until it times out - never actually logging in. I tried your code and it does the same thing as mine above. – jest3rz Sep 20 '19 at 21:09
  • @jest3rz _...continuously loads..._ Do you have a valid demo credential for us? The error message is so clear _email/password are invalid_ – undetected Selenium Sep 20 '19 at 21:16
  • the information that selenium is entering for me is the same I enter myself on google chrome and it takes my right through to the next page. I am unable to create a new account to login because you need a membership number to do so which would cost extra money. Maybe someone else will have a costco membership and they can try logging in as well. Could it have something to do with Headers or Post ? – jest3rz Sep 20 '19 at 21:20