How do I get Selenium to login to the website Costco.com

雨燕双飞 提交于 2019-12-02 09:05:22

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()

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!