[text] H

Viewer

  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.options import Options
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. from selenium.common.exceptions import TimeoutException
  7.  
  8. # Configure Chrome options
  9. chrome_options = Options()
  10. chrome_options.add_argument("--headless")
  11. chrome_options.add_argument("--no-sandbox")
  12.  
  13. # Initialize WebDriver
  14. driver = webdriver.Chrome(options=chrome_options)
  15. driver.get("https://toolkit.tesco.com/sign-in/")
  16.  
  17. try:
  18.     # Locate and click the "Partner sign in" button
  19.     partner_sign_in_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Partner sign-in")))
  20.     partner_sign_in_button.click()
  21.  
  22.     # Wait for the email address field to appear
  23.     username_field = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, 'email-address')))
  24.     
  25.     # Fill in the email address and password fields
  26.     username_field.send_keys('[email protected]')
  27.     password_field = driver.find_element(By.NAME, 'password')
  28.     password_field.send_keys('Pladmarch11')
  29.  
  30.     # Click the "Sign in" button
  31.     login_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//button[contains(text(), "Sign in")]')))
  32.     login_button.click()
  33.  
  34. except TimeoutException:
  35.     print("Timeout error: Unable to locate login elements.")
  36.  
  37. # Close the WebDriver session
  38. driver.quit()

Editor

You can edit this paste and save as new:


File Description
  • H
  • Paste Code
  • 23 Apr-2024
  • 1.5 Kb
You can Share it: